Skip to main content

ArgumentBuilder

Struct ArgumentBuilder 

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

Consuming builder for Argument.

Obtain via Argument::builder. Call ArgumentBuilder::build when done.

§Examples

let arg = Argument::builder("format")
    .description("Output format")
    .default_value("text")
    .build()
    .unwrap();

assert_eq!(arg.default.as_deref(), Some("text"));
assert!(!arg.required);

Implementations§

Source§

impl ArgumentBuilder

Source

pub fn description(self, d: impl Into<String>) -> Self

Set the human-readable description for this argument.

Source

pub fn required(self) -> Self

Mark this argument as required.

The parser will return crate::ParseError::MissingArgument if the argument is absent from the invocation.

Source

pub fn default_value(self, d: impl Into<String>) -> Self

Set the default value used when this argument is not provided.

A default value is only meaningful for optional (non-required) arguments. If the argument is required and has a default, the default is still stored but the parser will still require the argument to be supplied.

Source

pub fn variadic(self) -> Self

Mark this argument as variadic (consumes all remaining tokens).

A variadic argument must be the last argument defined on the command. crate::CommandBuilder::build enforces this constraint and returns crate::BuildError::VariadicNotLast if a variadic argument is followed by another argument.

Source

pub fn build(self) -> Result<Argument, BuildError>

Consume the builder and return an Argument.

§Errors

Returns BuildError::EmptyCanonical if the argument name is empty or consists entirely of whitespace.

§Examples
assert!(Argument::builder("env").build().is_ok());
assert_eq!(Argument::builder("").build().unwrap_err(), BuildError::EmptyCanonical);

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.