Skip to main content

LayerCtx

Struct LayerCtx 

Source
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

Source

pub fn new(registry: Registry) -> Self

Source

pub fn registry(&self) -> Registry

Source

pub fn prop(&self, key: &str) -> Option<Lookup>

The setting a dotted key names, following renames.

Source

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.

Source

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

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.