Skip to main content

OptionRegistry

Struct OptionRegistry 

Source
pub struct OptionRegistry { /* private fields */ }
Expand description

The project-wide registry of option definitions (the “common structure”).

It records one OptionDef per option name and rejects any attempt to (re)define that name with a different shape. It does not store value resolvers — those are per-command and attach to nodes directly.

Implementations§

Source§

impl OptionRegistry

Source

pub fn new() -> Self

Source

pub fn define(&mut self, def: &OptionDef) -> Result<(), OptionConflict>

Record def for its name, or verify it matches the existing record.

  • first time a name is seen → recorded.
  • seen again with an equal definition → accepted (shared use).
  • seen again with a different definition → OptionConflict.
Source

pub fn attach( &mut self, opt: &dyn CommandOption, ) -> Result<(OptionDef, Option<ValueProvider>), OptionConflict>

Validate a CommandOption attachment and yield its per-command value resolver. The definition is checked for consistency; the resolver (which may vary per command) is returned for the caller to attach to that command’s node.

Source

pub fn get(&self, name: &str) -> Option<&OptionDef>

The canonical definition recorded for an option name, if any.

Source

pub fn len(&self) -> usize

Number of distinct option names defined.

Source

pub fn is_empty(&self) -> bool

Source

pub fn audit(&self, observed: &[(String, OptionDef)]) -> Vec<ParseMismatch>

Runtime enforcement of “one parse-definition per option name” against the actual parser.

observed is every (command_path, OptionDef) extracted from the real command/argument tree (e.g. the clap Command). For each option name the audit collects the distinct parse_sigs seen — plus the registered canonical definition, if any — and reports a ParseMismatch for every name that has more than one. This catches the case the registry’s define alone cannot: two commands declaring the same flag with different arities, even though neither went through the shared definition.

Trait Implementations§

Source§

impl Debug for OptionRegistry

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for OptionRegistry

Source§

fn default() -> OptionRegistry

Returns the “default value” for a type. 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> 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.