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.

Implementations on Foreign Types§

source§

impl<'a> CreateOption for Cow<'a, str>

source§

fn create_option(data: CreateOptionData) -> CommandOption

source§

impl CreateOption for Attachment

source§

fn create_option(data: CreateOptionData) -> CommandOption

source§

impl CreateOption for bool

source§

fn create_option(data: CreateOptionData) -> CommandOption

source§

impl CreateOption for i64

source§

fn create_option(data: CreateOptionData) -> CommandOption

source§

impl CreateOption for InteractionChannel

source§

fn create_option(data: CreateOptionData) -> CommandOption

source§

impl CreateOption for Id<UserMarker>

source§

fn create_option(data: CreateOptionData) -> CommandOption

source§

impl CreateOption for Id<RoleMarker>

source§

fn create_option(data: CreateOptionData) -> CommandOption

source§

impl CreateOption for Role

source§

fn create_option(data: CreateOptionData) -> CommandOption

source§

impl CreateOption for Id<ChannelMarker>

source§

fn create_option(data: CreateOptionData) -> CommandOption

source§

impl CreateOption for User

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<AttachmentMarker>

source§

fn create_option(data: CreateOptionData) -> CommandOption

source§

impl CreateOption for String

source§

fn create_option(data: CreateOptionData) -> CommandOption

source§

impl CreateOption for f64

source§

fn create_option(data: CreateOptionData) -> CommandOption

Implementors§