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
impl CommandBuilder
Sourcepub fn new<S, M>(name: &str, description: Option<&str>, handler: S) -> Self
pub fn new<S, M>(name: &str, description: Option<&str>, handler: S) -> Self
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 subcommandhandler: The handler system for this command. This must be a system that takes at minimum anIn<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.
Sourcepub fn with_argument<T: Argument>(
&mut self,
name: &str,
description: Option<&str>,
optional: bool,
) -> &mut Self
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.
Sourcepub fn with_subcommands<B>(&mut self, builder: B) -> &mut Selfwhere
B: FnOnce(&mut SubcommandGroupBuilder),
pub fn with_subcommands<B>(&mut self, builder: B) -> &mut Selfwhere
B: FnOnce(&mut SubcommandGroupBuilder),
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
impl Hash for CommandBuilder
Source§impl PartialEq for CommandBuilder
impl PartialEq for CommandBuilder
impl Eq for CommandBuilder
Auto Trait Implementations§
impl Freeze for CommandBuilder
impl !RefUnwindSafe for CommandBuilder
impl Send for CommandBuilder
impl Sync for CommandBuilder
impl Unpin for CommandBuilder
impl !UnwindSafe for CommandBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSend for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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