Derive Macro DeriveActiveEnum
#[derive(DeriveActiveEnum)]
{
// Attributes available to this derive:
#[sea_orm]
}
Expand description
A derive macro to implement sea_orm::ActiveEnum trait for enums.
§Limitations
This derive macros can only be used on enums.
§Macro Attributes
All macro attributes listed below have to be annotated in the form of #[sea_orm(attr = value)].
-
For enum
rs_type: DefineActiveEnum::Value- Possible values:
String,i8,i16,i32,i64,u8,u16,u32,u64 - Note that value has to be passed as string, i.e.
rs_type = "i8"
- Possible values:
db_type: DefineColumnTypereturned byActiveEnum::db_type()- Possible values: all available enum variants of
ColumnType, e.g.String(StringLen::None),String(StringLen::N(1)),Integer - Note that value has to be passed as string, i.e.
db_type = "Integer"
- Possible values: all available enum variants of
enum_name: DefineStringreturned byActiveEnum::name()- This attribute is optional with default value being the name of enum in camel-case
- Note that value has to be passed as string, i.e.
enum_name = "MyEnum"
-
For enum variant
string_valueornum_value:- For
string_value, value should be passed as string, i.e.string_value = "A"- Due to the way internal Enums are automatically derived, the following restrictions apply:
- members cannot share identical
string_value, case-insensitive. - in principle, any future Titlecased Rust keywords are not valid
string_value.
- members cannot share identical
- Due to the way internal Enums are automatically derived, the following restrictions apply:
- For
num_value, value should be passed as integer, i.e.num_value = 1ornum_value = 1i32 - Note that only one of it can be specified, and all variants of an enum have to annotate with the same
*_valuemacro attribute
- For
§Usage
use sea_orm::{entity::prelude::*, DeriveActiveEnum};
#[derive(EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "i32", db_type = "Integer")]
pub enum Color {
Black = 0,
White = 1,
}