Skip to main content

Module options

Module options 

Source
Expand description

The neutral, ordered value tree a port entry carries between the config layer and the adapter that understands it.

The config crate reads [source], [stream], and [sinks.<name>] as a type plus whatever else is there, without interpreting it. That remainder is an Options map. The adapter for that type turns it into its own config struct with Options::deserialize_into, where serde’s deny_unknown_fields rejects a typo. The kernel therefore names no adapter and no file format, yet every option still validates strictly, one layer later.

OptionValue is one node of the tree: a scalar, an array, or a map with sorted keys. Sorted keys are what make a compiled lock byte-stable.

use kernel::Options;
use serde::Deserialize;

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
struct Channel { capacity: usize }

let options: Options = toml::from_str(r#"capacity = 512"#).unwrap();
let channel: Channel = options.clone().deserialize_into().unwrap();
assert_eq!(channel.capacity, 512);

let typo: Options = toml::from_str(r#"capacty = 512"#).unwrap();
let error = typo.deserialize_into::<Channel>().unwrap_err().to_string();
assert!(error.contains("unknown field `capacty`"), "{error}");

Structs§

Options
The options of one port entry: everything under [source], [stream], or [sinks.<name>] except its type, keyed in sorted order.
OptionsError
An options tree could not be turned into an adapter’s config (or back): a missing or unknown field, a wrong type, an out-of-range number. The message names the field.

Enums§

OptionValue
One node of an options tree.