Skip to content

Commit

Permalink
Rename from_toml() for consistency with to_toml()
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Oct 22, 2023
1 parent a056cad commit fc61b18
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ pub(crate) struct Config {
impl Config {
pub(crate) fn load<P: AsRef<Path>>(path: P) -> Result<Config, ConfigError> {
match std::fs::read_to_string(&path) {
Ok(s) => Config::from_toml_string(&s),
Ok(s) => Config::from_toml(&s),
Err(source) => Err(ConfigError::Read {
path: path.as_ref().to_owned(),
source,
}),
}
}

pub(crate) fn from_toml_string(s: &str) -> Result<Config, ConfigError> {
pub(crate) fn from_toml(s: &str) -> Result<Config, ConfigError> {
toml::from_str::<Config>(s).map_err(ConfigError::from)
}

Expand Down Expand Up @@ -277,7 +277,7 @@ mod tests {
color = "blue"
description = "Bar all the foos"
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let r = cfg.get_profile("mine");
assert_matches!(r, Err(ConfigError::NoSuchProfile(name)) => {
assert_eq!(name, "mine");
Expand Down Expand Up @@ -341,7 +341,7 @@ mod tests {
color = "green"
description = "Clee all the shs"
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let defprofile = cfg.get_default_profile().unwrap();
assert_eq!(defprofile.name, "mine");
assert_eq!(
Expand Down Expand Up @@ -388,7 +388,7 @@ mod tests {
color = "green"
description = "Clee all the shs"
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let r = cfg.get_default_profile();
assert_matches!(r, Err(ConfigError::NoSuchProfile(name)) => {
assert_eq!(name, "default");
Expand Down Expand Up @@ -439,7 +439,7 @@ mod tests {
color = "blue"
description = "Bar all the foos"
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let r = cfg.get_default_profile();
assert_matches!(r, Err(ConfigError::RepeatedLabel(name)) => {
assert_eq!(name, "Foo");
Expand All @@ -459,7 +459,7 @@ mod tests {
color = "blue"
description = "Bar all the foos"
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let default = cfg.get_profile("default").unwrap();
assert_eq!(default.name, "default");
assert_eq!(
Expand Down Expand Up @@ -510,7 +510,7 @@ mod tests {
color = "blue"
description = "Bar all the foos"
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let r = cfg.get_default_profile();
assert_matches!(r, Err(ConfigError::LabelRenamed { label, renamer }) => {
assert_eq!(label, "BAR");
Expand All @@ -532,7 +532,7 @@ mod tests {
description = "Bar all the foos"
rename-from = ["foo"]
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let r = cfg.get_default_profile();
assert_matches!(r, Err(ConfigError::LabelRenamed { label, renamer }) => {
assert_eq!(label, "foo");
Expand All @@ -555,7 +555,7 @@ mod tests {
description = "Bar all the foos"
rename-from = ["quux"]
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let r = cfg.get_default_profile();
assert_matches!(r, Err(ConfigError::RenameConflict {
renamed,
Expand All @@ -582,7 +582,7 @@ mod tests {
color = "blue"
description = "Bar all the foos"
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let defprofile = cfg.get_default_profile().unwrap();
assert_eq!(defprofile.name, "default");
assert_eq!(
Expand Down Expand Up @@ -630,7 +630,7 @@ mod tests {
color = "blue"
description = "Bar all the foos"
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let r = cfg.get_default_profile();
assert_matches!(r, Err(ConfigError::SelfRename(name)) => {
assert_eq!(name, "foo");
Expand All @@ -653,7 +653,7 @@ mod tests {
enforce-case = false
on-rename-clash = "ignore"
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let defprofile = cfg.get_default_profile().unwrap();
assert_eq!(defprofile.name, "default");
assert_eq!(
Expand Down Expand Up @@ -704,7 +704,7 @@ mod tests {
description = "Bar all the foos"
create = true
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let defprofile = cfg.get_default_profile().unwrap();
assert_eq!(defprofile.name, "default");
assert_eq!(
Expand Down Expand Up @@ -755,7 +755,7 @@ mod tests {
description = "Bar all the foos"
create = true
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let defprofile = cfg.get_default_profile().unwrap();
assert_eq!(defprofile.name, "default");
assert_eq!(
Expand Down Expand Up @@ -814,7 +814,7 @@ mod tests {
on-rename-clash = "warn"
enforce-case = false
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let defprofile = cfg.get_default_profile().unwrap();
assert_eq!(defprofile.name, "default");
assert_eq!(
Expand Down Expand Up @@ -876,7 +876,7 @@ mod tests {
name = "Foo"
description = "Bar all the foos"
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let default = cfg.get_profile("default").unwrap();
assert_eq!(default.name, "default");
assert_eq!(
Expand Down Expand Up @@ -933,7 +933,7 @@ mod tests {
color = "red"
description = "Foo all the bars"
"#};
let cfg = Config::from_toml_string(s).unwrap();
let cfg = Config::from_toml(s).unwrap();
let defprofile = cfg.get_default_profile().unwrap();
assert_eq!(defprofile.name, "default");
assert_eq!(
Expand Down

0 comments on commit fc61b18

Please sign in to comment.