CreateOption

Trait CreateOption 

Source
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.

AttributeTypeLocationDescription
namestrVariantSet the name of the command option choice.
name_localizationsfn1VariantLocalized name of the command option choice.
valuestr, i64 or f64VariantValue of the command option choice.

  1. Path to a function that returns a type that implements IntoIterator<Item = (ToString, ToString)>. See the module documentation to learn more. 

Required Methods§

Source

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.

Implementations on Foreign Types§

Source§

impl CreateOption for Cow<'_, str>

Source§

fn create_option(data: CreateOptionData) -> CommandOption

Source§

impl CreateOption for bool

Source§

fn create_option(data: CreateOptionData) -> CommandOption

Source§

impl CreateOption for f64

Source§

fn create_option(data: CreateOptionData) -> CommandOption

Source§

impl CreateOption for i64

Source§

fn create_option(data: CreateOptionData) -> CommandOption

Source§

impl CreateOption for String

Source§

fn create_option(data: CreateOptionData) -> CommandOption

Source§

impl CreateOption for InteractionChannel

Source§

fn create_option(data: CreateOptionData) -> CommandOption

Source§

impl CreateOption for Attachment

Source§

fn create_option(data: CreateOptionData) -> CommandOption

Source§

impl CreateOption for Role

Source§

fn create_option(data: CreateOptionData) -> CommandOption

Source§

impl CreateOption for Id<AttachmentMarker>

Source§

fn create_option(data: CreateOptionData) -> CommandOption

Source§

impl CreateOption for Id<ChannelMarker>

Source§

fn create_option(data: CreateOptionData) -> CommandOption

Source§

impl CreateOption for Id<GenericMarker>

Source§

fn create_option(data: CreateOptionData) -> CommandOption

Source§

impl CreateOption for Id<RoleMarker>

Source§

fn create_option(data: CreateOptionData) -> CommandOption

Source§

impl CreateOption for Id<UserMarker>

Source§

fn create_option(data: CreateOptionData) -> CommandOption

Source§

impl CreateOption for User

Source§

fn create_option(data: CreateOptionData) -> CommandOption

Implementors§