pub enum Source {
Folder(PathBuf),
File(PathBuf),
String {
format: FormatKind,
content: String,
},
Value(Result<Value, String>),
}Expand description
One config source. Sources merge in order — later overrides earlier.
Variants§
Folder(PathBuf)
File(PathBuf)
String
An in-code string; its format may be a built-in or a
[CustomFormat] (no formats registration needed — the source
names its parser directly).
Value(Result<Value, String>)
An in-code serde value (Source::value) — already converted to
a Value, or the serialization error to report at load time.
Implementations§
Source§impl Source
impl Source
Sourcepub fn folder(path: impl Into<PathBuf>) -> Self
pub fn folder(path: impl Into<PathBuf>) -> Self
Accepts anything path-like: &str, String, &Path, PathBuf.
Sourcepub fn file(path: impl Into<PathBuf>) -> Self
pub fn file(path: impl Into<PathBuf>) -> Self
Accepts anything path-like: &str, String, &Path, PathBuf.
Sourcepub fn string(format: impl Into<FormatKind>, content: impl Into<String>) -> Self
pub fn string(format: impl Into<FormatKind>, content: impl Into<String>) -> Self
An in-code config string — the hook for overriding values
manually. Takes a [Format] or a [CustomFormat].
Sourcepub fn value(value: impl Serialize) -> Self
pub fn value(value: impl Serialize) -> Self
An in-code serde value — typed overrides without going through a
format parser (works with any #[derive(Serialize)] type, no
format feature needed). A serialization failure (e.g. a map with
non-string keys) surfaces at load time; a Null root (e.g.
None) contributes nothing, like every other source.
#[derive(serde::Serialize)]
struct Overrides {
debug: bool,
}
let value: c4::Value = c4::Loader::new(c4::Options {
sources: vec![c4::Source::value(Overrides { debug: true })],
..c4::Options::default()
})
.load()?;
assert_eq!(value["debug"].as_bool(), Some(true));