Refactor
This commit is contained in:
parent
461aa925f6
commit
e3f64b1892
@ -89,7 +89,7 @@ impl ActiveEnum {
|
|||||||
_ => return Err(Error::InputNotEnum),
|
_ => return Err(Error::InputNotEnum),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut is_string = false;
|
let mut is_string = rename_all_rule.is_some();
|
||||||
let mut is_int = false;
|
let mut is_int = false;
|
||||||
let mut variants = Vec::new();
|
let mut variants = Vec::new();
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ impl ActiveEnum {
|
|||||||
.map_err(Error::Syn)?;
|
.map_err(Error::Syn)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_string || rename_rule.is_some() || rename_all_rule.is_some()) && is_int {
|
if is_string && is_int {
|
||||||
return Err(Error::TT(quote_spanned! {
|
return Err(Error::TT(quote_spanned! {
|
||||||
ident_span => compile_error!("All enum variants should specify the same `*_value` macro attribute, either `string_value` or `num_value` but not both");
|
ident_span => compile_error!("All enum variants should specify the same `*_value` macro attribute, either `string_value` or `num_value` but not both");
|
||||||
}));
|
}));
|
||||||
|
@ -46,6 +46,16 @@ pub enum TestEnum2 {
|
|||||||
HelloWorldTwo,
|
HelloWorldTwo,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, EnumIter, DeriveActiveEnum, Eq, PartialEq)]
|
||||||
|
#[sea_orm(
|
||||||
|
rs_type = "String",
|
||||||
|
db_type = "String(StringLen::None)",
|
||||||
|
rename_all = "snake_case"
|
||||||
|
)]
|
||||||
|
pub enum TestEnum3 {
|
||||||
|
HelloWorld,
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn derive_active_enum_value() {
|
fn derive_active_enum_value() {
|
||||||
assert_eq!(TestEnum::DefaultVariant.to_value(), "defaultVariant");
|
assert_eq!(TestEnum::DefaultVariant.to_value(), "defaultVariant");
|
||||||
@ -124,4 +134,6 @@ fn derive_active_enum_from_value() {
|
|||||||
fn derive_active_enum_value_2() {
|
fn derive_active_enum_value_2() {
|
||||||
assert_eq!(TestEnum2::HelloWorld.to_value(), "hello_world");
|
assert_eq!(TestEnum2::HelloWorld.to_value(), "hello_world");
|
||||||
assert_eq!(TestEnum2::HelloWorldTwo.to_value(), "helloWorldTwo");
|
assert_eq!(TestEnum2::HelloWorldTwo.to_value(), "helloWorldTwo");
|
||||||
|
|
||||||
|
assert_eq!(TestEnum3::HelloWorld.to_value(), "hello_world");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user