Skip to main content

Registry

Struct Registry 

Source
pub struct Registry {
    pub props: &'static [PropMeta],
}
Expand description

Every setting a CLI has.

Fields§

§props: &'static [PropMeta]

Implementations§

Source§

impl Registry

Source

pub const fn new(props: &'static [PropMeta]) -> Self

Source

pub fn get(&self, id: PropId) -> &'static PropMeta

Source

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

The id of a dotted key, following a rename to the setting that replaced it.

Linear, because a registry is small and a lookup happens once per key a layer supplies — not once per key that exists. A binary search over a sorted table would be a fine optimization and is not yet worth the invariant it demands of the generator.

Source

pub fn lookup_exact(&self, key: &str) -> Option<PropId>

The id of a dotted key, without following a rename.

Registry::lookup answers “which setting does this key mean”, which is what a reader wants. This answers “which declaration is this key”, which is what a warning wants: the deprecation message lives on the old name’s own declaration.

Source

pub fn names_file_value(&self, key: &str) -> bool

Whether a table at key is itself a setting value rather than a path to more-specific settings.

Aliases participate in file lookup, but an alias that is also the prefix of a declared dotted key must not swallow that nested value. A leaf alias for a map or object still names the whole table.

Source

pub fn deprecation_meta(&self, key: &str) -> Option<&'static PropMeta>

The first deprecated declaration along the rename chain that starts at key.

The chain, not the declaration named: a renamed to b, and b the one carrying the notice that says to use c. A user who wrote a is being told the same thing either way, and which release the notice was attached in is not something they can see.

Bounded by the number of settings there are, so a registry whose renames form a cycle stops rather than following them forever — the same guard Registry::lookup uses, and for the same reason: this is an authoring mistake, and hanging is a worse way to report one than nothing at all. The derive refuses such a declaration outright.

Source

pub fn deprecation(&self, key: &str) -> Option<&'static str>

The first deprecation notice along the rename chain that starts at key.

Kept as the message-only counterpart to Registry::deprecation_meta for callers that do not need lifecycle milestones.

Source

pub fn ids(&self) -> impl Iterator<Item = PropId>

The settings an environment variable sets, and the variable that set them.

Several names per setting are aliases in descending precedence, which the env layer honours by taking the first one that is present.

Source

pub fn drift(&self, bound: &[(&str, &str)]) -> Vec<String>

Every way the flags a spec declares and the flags a CLI binds disagree.

Empty means they agree. This is the check hk needed and did not have: it declares eighteen sources.cli bindings and reads five, because the declaration lives in a spec and the reading lives in a hand-written struct, and nothing has ever compared the two. A spec that documents --jobs and a CLI that never puts it anywhere is a promise to a user that no test could catch.

bound is what the CLI actually does: pairs of a flag and the setting it sets. A CLI whose flags come from usage::Cli can generate that list; one that binds by hand writes it out, which is still one list rather than two behaviours.

Both directions are reported, because they are different mistakes. A declared flag nothing binds is documentation for something that does not happen. A bound flag the setting does not declare happens without being documented — the user cannot discover it, and explain cannot name it.

Source

pub fn bindings( &self, kind: SourceKind, ) -> impl Iterator<Item = (PropId, &'static str)> + use<'_>

Every setting bound to kind, with its key in that source.

The generic mechanism a custom layer is written against: a git layer asks for "git" and reads the keys it gets back, without usage knowing anything about git.

Trait Implementations§

Source§

impl Clone for Registry

Source§

fn clone(&self) -> Registry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Registry

Source§

impl Debug for Registry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.