Skip to content

Commit

Permalink
config: add convenient function that constructs ConfigLayer from TOML…
Browse files Browse the repository at this point in the history
… string

This will be used mainly in tests. The default layers might also be migrated to
per-file layers constructed by ConfigLayer::parse().
  • Loading branch information
yuja committed Nov 30, 2024
1 parent d76bcd9 commit 512d85b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ impl ConfigLayer {
}
}

/// Parses TOML document `text` into new layer.
pub fn parse(source: ConfigSource, text: &str) -> Result<Self, ConfigError> {
let data = config::Config::builder()
.add_source(config::File::from_str(text, config::FileFormat::Toml))
.build()?;
Ok(Self::with_data(source, data))
}

fn load_from_file(source: ConfigSource, path: PathBuf) -> Result<Self, ConfigError> {
// TODO: will be replaced with toml_edit::DocumentMut or ImDocument
let data = config::Config::builder()
Expand Down

0 comments on commit 512d85b

Please sign in to comment.