Skip to main content

Inputs

Struct Inputs 

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

Name-keyed storage for resolved inputs.

Each entry stores the resolved T value boxed as dyn Any + Send + Sync, while its InputSourceKind metadata is tracked separately on the internal entry. Lookups are by (name, T) — wrong-type lookups return None rather than panicking.

Names are stored as Cow<'static, str> so both string literals and runtime-generated names (e.g. config-driven command setups) work without leaking memory.

Implementations§

Source§

impl Inputs

Source

pub fn new() -> Self

Create an empty Inputs bag.

Source

pub fn insert<T>( &mut self, name: impl Into<Cow<'static, str>>, resolved: ResolvedInput<T>, ) -> Option<InputSourceKind>
where T: Send + Sync + 'static,

Insert a resolved input under name.

name accepts anything convertible into Cow<'static, str> — string literals ("body"), owned Strings, and explicit Cows all work.

Returns the previous entry’s source kind if name was already present.

Source

pub fn get<T: 'static>(&self, name: &str) -> Option<&T>

Get a reference to the value stored under name, if it exists and has type T.

Returns None if no entry exists or the stored type does not match.

Source

pub fn get_required<T: 'static>(&self, name: &str) -> Result<&T, MissingInput>

Get the value stored under name, returning a descriptive error if missing or of the wrong type.

Source

pub fn source_of(&self, name: &str) -> Option<InputSourceKind>

Get the InputSourceKind that provided name, if it exists.

Source

pub fn contains(&self, name: &str) -> bool

Returns true if name has been resolved.

Source

pub fn len(&self) -> usize

Number of resolved inputs.

Source

pub fn is_empty(&self) -> bool

Returns true if no inputs have been resolved.

Source

pub fn iter_sources(&self) -> impl Iterator<Item = (&str, InputSourceKind)> + '_

Iterate over (name, source) pairs.

Trait Implementations§

Source§

impl Debug for Inputs

Source§

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

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

impl Default for Inputs

Source§

fn default() -> Inputs

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.