Skip to main content

Choice

Trait Choice 

Source
pub trait Choice:
    Sized
    + Clone
    + 'static {
    // Required methods
    fn value(&self) -> &str;
    fn title(&self) -> &str;
}
Expand description

A trait for defining choices in a choice set setting.

The trait has already been implemented for String, &str, and tuples of (&str, &str).

You can implement this trait for your own types to use them in a ChoiceSetSetting (as long as their value don’t collide with each other):


#[derive(Debug, Clone)]
enum TextSize {
    Small,
    Medium,
    Large
}

impl Choice for TextSize {
    fn value(&self) -> &str {
        match self {
            TextSize::Small => "small",
            TextSize::Medium => "medium",
            TextSize::Large => "large",
        }
    }
    fn title(&self) -> &str {
        match self {
           TextSize::Small => "Small",
           TextSize::Medium => "Medium",
          TextSize::Large => "Large",
       }
    }   
}

Required Methods§

Source

fn value(&self) -> &str

Returns the value of the choice.

This value should be unique across all choices in the set.

Source

fn title(&self) -> &str

Returns the title of the choice.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Choice for &'static str

Source§

fn value(&self) -> &str

Source§

fn title(&self) -> &str

Source§

impl Choice for (&'static str, &'static str)

Source§

fn value(&self) -> &str

Source§

fn title(&self) -> &str

Source§

impl Choice for String

Source§

fn value(&self) -> &str

Source§

fn title(&self) -> &str

Implementors§