Skip to main content

Options

Trait Options 

Source
pub trait Options {
    // Required method
    fn options() -> Vec<(String, String)>;

    // Provided method
    fn label_of(value: &str) -> String { ... }
}
Expand description

A closed set of stored values, each with its label.

Derive it on a unit-variant enum with #[derive(Options)]: each variant stores its snake_case name and reads as its name in sentence case, and #[option(value = "..", label = "..")] overrides either.

#[derive(Debug, Clone, Copy, PartialEq, Eq, tablo_core::Options)]
enum Status {
    Draft,
    #[option(label = "Live")]
    Published,
}

Field::choice(Post::fields().status()).options(Status::options());
SelectFilter::new(Post::fields().status(), Status::options());
TextColumn::new(lens!(Post.status)).format(|status| Status::label_of(status));

The derive also gives the enum value(), label() and from_value(), so code that writes the column names a variant rather than a string.

Required Methods§

Source

fn options() -> Vec<(String, String)>

Every option as (value, label), in declaration order.

Provided Methods§

Source

fn label_of(value: &str) -> String

The label of a stored value, or value itself when no option stores it: a row written before an option was renamed still reads.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§