CommandBuilder

Struct CommandBuilder 

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

A command builder.

Commands are comprised of a tree of command nodes, a command name, an optional command description, and a handler system. Handler systems may behave like normal systems, except that they must receive the In<CommandContext> parameter and return CommandResult.

The order that command nodes (argument or subcommand group) are added with their respective with_ methods determines the order they are parsed in, and therefore the layout of the command.

Implementations§

Source§

impl CommandBuilder

Source

pub fn new<S, M>(name: &str, description: Option<&str>, handler: S) -> Self
where S: IntoSystem<In<CommandContext>, CommandResult, M> + Send + Sync + 'static,

Create a new command.

  • name: The name of this command. This currently may not begin with a digit ('0'..='9') and may otherwise only contain the characters 'a'..='z', 'A'..='Z', '0'..='9', and _. This limitation may be lifted in the future.
  • description: An optional description for this subcommand
  • handler: The handler system for this command. This must be a system that takes at minimum an In<CommandContext>.

A common error when using this with a closure as a handler is when one omits the type of In<CommandContext>, e.g.:

use bevy_commodore::CommandBuilder;

// rust cannot correctly determine the type of the closure when the type of `v` is omitted.
CommandBuilder::new("empty", None, |v| todo!());

In this case, simply add the type to the closure:

use bevy::prelude::In;
use bevy_commodore::{CommandBuilder, CommandContext};

CommandBuilder::new("empty", None, |v: In<CommandContext>| todo!());
§Panics

Panics if the name does not match the above specified predicate.

Source

pub fn with_argument<T: Argument>( &mut self, name: &str, description: Option<&str>, optional: bool, ) -> &mut Self

Add an argument node to this command. Arguments are stored - and therefore parsed - in the order that they are passed to this function.

T must be an argument type that has been registered to the plugin.

Source

pub fn with_subcommands<B>(&mut self, builder: B) -> &mut Self

Add a subcommand group node to this command. A subcommand group node is a group of subcommands, from which the user may select one.

This method takes a closure which is passed a &mut SubcommandGroupBuilder.

§Panics

This method panics if no subcommands were added to the SubcommandGroupBuilder.

Trait Implementations§

Source§

impl Hash for CommandBuilder

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CommandBuilder

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for CommandBuilder

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynEq for T
where T: Any + Eq,

Source§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
Source§

impl<T> DynHash for T
where T: DynEq + Hash,

Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Feeds this value into the given Hasher.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. 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.
Source§

impl<T> ConditionalSend for T
where T: Send,