pub struct LayerCtx { /* private fields */ }Expand description
What a layer is given while it reads.
The registry, and the helpers that keep every layer honest about the same two things: a key it does not recognize is a warning rather than an error, and a raw string becomes a value the way the spec says rather than the way the layer guesses.
Implementations§
Source§impl LayerCtx
impl LayerCtx
pub fn new(registry: Registry) -> Self
pub fn registry(&self) -> Registry
Sourcepub fn prop(&self, key: &str) -> Option<Lookup>
pub fn prop(&self, key: &str) -> Option<Lookup>
The setting a dotted key names, following renames.
Sourcepub fn parse(&self, id: PropId, raw: &str) -> Result<Value, TypeError>
pub fn parse(&self, id: PropId, raw: &str) -> Result<Value, TypeError>
A raw string read as the setting’s declared type, applying its named parser first.
Every layer that reads text should come through here. A layer that decides for itself how to split a list is how two sources of the same setting end up disagreeing about what a comma means.
Sourcepub fn entry(
&self,
id: PropId,
raw: &str,
origin: Origin,
) -> Result<Entry, Warning>
pub fn entry( &self, id: PropId, raw: &str, origin: Origin, ) -> Result<Entry, Warning>
An entry for id, with raw read as the declared type.
The shape almost every layer wants: on a value that cannot be the declared type, the entry is dropped and a warning takes its place, naming the origin. A bad value in a system-wide file must not stop a CLI from starting.
Source§impl LayerCtx
impl LayerCtx
Sourcepub fn entry_for_key(
&self,
key: &str,
raw: &str,
origin: Origin,
) -> Result<Entry, Warning>
pub fn entry_for_key( &self, key: &str, raw: &str, origin: Origin, ) -> Result<Entry, Warning>
An entry for a dotted key, which is what a layer reading a file has in hand.
The path worth taking: it looks the key up, follows a rename while remembering the name that was written, reads the value as the declared type, and turns an unknown key into a warning rather than an error — everything a layer would otherwise have to remember to do, and the reason a deprecated key in somebody’s config file gets reported at all.
Sourcepub fn entry_from_value(
&self,
key: &str,
value: Value,
origin: Origin,
) -> Result<Entry, Warning>
pub fn entry_from_value( &self, key: &str, value: Value, origin: Origin, ) -> Result<Entry, Warning>
An entry for a dotted key whose value already has a shape.
A file has structure of its own — an array is an array, a table is a table — and there is
no text a named parser could turn into one, so a layer reading a structured format hands
the value over as it found it. It still goes through the declared type, which is what
keeps the promise that a value of the wrong type costs a warning and not a wrong value:
a map<string, string> given a number inside it says so, rather than storing it.