The Serialized<T> provider allows you to source configuration values directly from any type T that implements serde::Serialize.
Unkeyed Data
If you do not provide a key, the serialized value T is expected to be a dictionary (map). It will be emitted directly at the root of the configured profile.
Keyed Data
If you provide a key (e.g., using .key("a.b.c")), the serialized value T can be any valid Value. Figment will automatically create nested dictionaries for every path component delimited by . in the key string. For example, a key of a.b.c results in a structure like { "a": { "b": { "c": T }}}.
Profiles
By default, data is emitted to Profile::Default. You can change this using .profile(P) where P implements Into<Profile>.
use figment::{Figment, providers::Serialized, util::map};
use serde::Deserialize;
#[derive(Debug, PartialEq, Deserialize)]
struct Config {
numbers: Vec<usize>,
}
// Example: Unkeyed provider (expects a map/dict)
let map = map!["numbers" => &[1, 2, 3]];
let figment = Figment::from(Serialized::from(&map, "default"));
let config: Config = figment.extract().unwrap();
assert_eq!(config, Config { numbers: vec![1, 2, 3] });