Skip to main content

BoundCliSpec

Struct BoundCliSpec 

Source
pub struct BoundCliSpec<R> { /* private fields */ }
Expand description

A built registry with exactly one handler per action.

Implementations§

Source§

impl<R> BoundCliSpec<R>

Source

pub fn resolve_from<I, S>(&self, args: I) -> Result<BoundOutcome<R>, CliError>
where I: IntoIterator<Item = S>, S: Into<OsString>,

Resolve argv against this registry, binding the run branch to its handler as it goes.

The handler is attached here, where bind_actions has already proved one exists for every action, which is what makes BoundInvocation::run infallible. Resolving through the registry that owns the handlers also removes the possibility of dispatching an invocation from a different registry: there is no longer a step that takes one.

Source

pub fn call_every_combination(&self) -> Vec<(String, R)>

Call every declared combination’s handler with strict argument reads, returning each combination id with what its handler produced.

This runs your handlers. Every one of them, on synthetic argv, in whatever order the registry declares them. Use it only where a handler is a pure projection of argv into a command value. Where the handler is the command, this will do whatever the command does — bind a port and never return, open a terminal, write files, or uninstall something. The name of this method is not a promise that it is safe to call; the shape of your handlers is.

Where it does fit, it is the other half of ResolvedInvocation::required being infallible. A handler that reads an argument id its combination does not declare gets a failed read in production — silent, and exactly the class of typo no compiler catches. Here it panics naming the combination and the id, driven by the same synthetic invocations BuiltCliSpec::synthetic_invocations generates for help and docs. Production code carries no branch for a case it cannot reach, and the case is still caught before it ships.

If your handlers are not callable here, that is worth reading as a design signal rather than a limitation of this method: separating “parse argv into a typed command” from “carry the command out” makes the check available and is the better shape independently.

The results are returned rather than discarded because a handler that returns a Result has a second thing worth checking — that every combination actually builds — and a caller that had to write its own loop for that would be back to hand-rolling the half this replaces. Ignore the return when the handler’s output says nothing useful.

Auto Trait Implementations§

§

impl<R> Freeze for BoundCliSpec<R>

§

impl<R> RefUnwindSafe for BoundCliSpec<R>

§

impl<R> Send for BoundCliSpec<R>

§

impl<R> Sync for BoundCliSpec<R>

§

impl<R> Unpin for BoundCliSpec<R>

§

impl<R> UnsafeUnpin for BoundCliSpec<R>

§

impl<R> UnwindSafe for BoundCliSpec<R>

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more