Skip to main content

CommandBuilder

Struct CommandBuilder 

Source
pub struct CommandBuilder<'r, 'a> { /* private fields */ }
Expand description

Fluent builder for registering a command with typed arguments.

Implementations§

Source§

impl<'r, 'a> CommandBuilder<'r, 'a>

Source

pub fn description(self, desc: &str) -> Self

Sets the command description (shown in /help).

Source

pub fn arg(self, name: &str, arg_type: Arg) -> Self

Adds a required argument with default validation.

Source

pub fn arg_with(self, name: &str, arg_type: Arg, validation: Validation) -> Self

Adds a required argument with custom validation.

Source

pub fn optional_arg(self, name: &str, arg_type: Arg) -> Self

Adds an optional argument with default validation.

Source

pub fn variant( self, build: impl FnOnce(VariantBuilder) -> VariantBuilder, ) -> Self

Adds a variant for polymorphic commands.

Each variant is a separate argument list. The parser tries variants in order and uses the first one that succeeds.

Source

pub fn handler( self, handler: impl Fn(&CommandArgs, &dyn Context) + Send + Sync + 'static, )

Sets the handler and registers the command.

Auto Trait Implementations§

§

impl<'r, 'a> Freeze for CommandBuilder<'r, 'a>

§

impl<'r, 'a> !RefUnwindSafe for CommandBuilder<'r, 'a>

§

impl<'r, 'a> !Send for CommandBuilder<'r, 'a>

§

impl<'r, 'a> !Sync for CommandBuilder<'r, 'a>

§

impl<'r, 'a> Unpin for CommandBuilder<'r, 'a>

§

impl<'r, 'a> UnsafeUnpin for CommandBuilder<'r, 'a>

§

impl<'r, 'a> !UnwindSafe for CommandBuilder<'r, 'a>

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.