Skip to main content

Options

Derive Macro Options 

Source
#[derive(Options)]
{
    // Attributes available to this derive:
    #[option]
}
Expand description

Derive Options for a unit-variant enum: the (value, label) list a choice field, a select filter and a column share, and the FormScalar that posts a variant as its value and reads it as its label.

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

assert_eq!(Status::Published.value(), "published");
assert_eq!(Status::Published.label(), "Live");
assert_eq!(Status::from_value("draft"), Some(Status::Draft));

Each variant’s value is its snake_case name and its label that name in sentence case. #[option(value = "..")] and #[option(label = "..")] override either. A generic enum, a variant with fields, two variants sharing one value or one label, and an unknown key are compile errors.

The enum, and an Option of it, is a form scalar through this derive, so it cannot also implement TypedValue or FormScalar itself. Derive Options for a unit-variant enum; documented on the tablo-core re-export.