pub trait SubCommand: Sized {
// Required methods
fn parse(
option: Option<&ApplicationCommandInteractionDataOption>,
) -> Result<Self, ParseError>;
fn register_sub_options(
option: &mut CreateApplicationCommandOption,
) -> &mut CreateApplicationCommandOption;
}Expand description
This trait provides the functions necessary to parse and register a subcommand for a slash command.
For most use cases:
// 1. Create the subcommand in the same way you would create a Command, but derive the
// SubCommand trait instead
// (Remember to implement ApplicationCommandInteractionHandler)
#[derive(Debug, SubCommand)]
struct TestSubCommandOne {
/// A number
number: f64,
}
#[derive(Debug, SubCommand)]
struct TestSubCommandTwo;
// 2. Create an enum with a variant for each subcommand and derive the Command and
// ApplicationCommandInteractionHandler traits:
/// A test command to show subcommands
#[derive(Debug, Command, ApplicationCommandInteractionHandler)]
#[name = "test"]
enum TestCommand {
/// The first subcommand
#[name = "one"]
One(TestSubCommandOne),
/// The second subcommand
#[name = "two"]
Two(TestSubCommandTwo),
}If there is a lot of shared behaviour between the subcommands, you may wish to directly implement
the ApplicationCommandInteractionHandler trait for this Command enum rather than for each
SubCommand.
To organize subcommands into groups, see the SubCommandGroup trait
Required Methods§
Sourcefn parse(
option: Option<&ApplicationCommandInteractionDataOption>,
) -> Result<Self, ParseError>
fn parse( option: Option<&ApplicationCommandInteractionDataOption>, ) -> Result<Self, ParseError>
Try to parse this from a command option
Sourcefn register_sub_options(
option: &mut CreateApplicationCommandOption,
) -> &mut CreateApplicationCommandOption
fn register_sub_options( option: &mut CreateApplicationCommandOption, ) -> &mut CreateApplicationCommandOption
Register any sub options for this subcommand
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.