pub trait CreateOption: Sized {
// Required method
fn create_option(data: CreateOptionData) -> CommandOption;
}Expand description
Create a command option from a type.
This trait is used by the implementation of CreateCommand generated
by the derive macro. See the module documentation for
a list of implemented types.
§Option choices
This trait can be derived on enums to represent command options with
predefined choices. The #[option] attribute must be present on each
variant.
§Example
use twilight_interactions::command::CreateOption;
#[derive(CreateOption)]
enum TimeUnit {
#[option(name = "Minute", value = 60)]
Minute,
#[option(name = "Hour", value = 3600)]
Hour,
#[option(name = "Day", value = 86400)]
Day,
}§Macro attributes
The macro provides an #[option] attribute to configure the generated code.
| Attribute | Type | Location | Description |
|---|---|---|---|
name | str | Variant | Set the name of the command option choice. |
name_localizations | fn1 | Variant | Localized name of the command option choice. |
value | str, i64 or f64 | Variant | Value of the command option choice. |
Path to a function that returns a type that implements
IntoIterator<Item = (ToString, ToString)>. See the module documentation to learn more. ↩
Required Methods§
Sourcefn create_option(data: CreateOptionData) -> CommandOption
fn create_option(data: CreateOptionData) -> CommandOption
Create a CommandOption from this type.
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.