macro_rules! sql_enum { ($(#[$enum_doc:meta])* Name => $name:ident, $($(#[$variant_doc:meta])* $vname:ident),* $(,)?) => { ... }; }
Expand description
Generate an SQL-compatible field-less enum.
SQL compatible means:
#[repr(i64)]- the equivalent of SQLite’sINTEGERtype.- Implements
TryFrom<i64>. - Implements
ToSqlandFromSql.
(Additionally, the standard constellation of Debug/Clone/Copy/Eq are derived.)
An enum generated by this macro can be used in any Model implementor.
Usage
sql_enum! {
Name => Color,
Red,
Green,
Blue,
};Notes
Explicit discriminants are not supported. This means that:
ⓘ
sql_enum! {
Name => Color,
Red = 1,
...
}…will not compile.
Discriminants will be implicitly numbered, in order of definition, from zero.
Doc comments are supported:
sql_enum! {
/// An RGB color tag.
Name => Color,
/// Red
Red,
/// Green
Green,
/// Blue
Blue,
}