Skip to content

Commit e3f64b1

Browse files
committed
Refactor
1 parent 461aa92 commit e3f64b1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

sea-orm-macros/src/derives/active_enum.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl ActiveEnum {
8989
_ => return Err(Error::InputNotEnum),
9090
};
9191

92-
let mut is_string = false;
92+
let mut is_string = rename_all_rule.is_some();
9393
let mut is_int = false;
9494
let mut variants = Vec::new();
9595

@@ -129,7 +129,7 @@ impl ActiveEnum {
129129
.map_err(Error::Syn)?;
130130
}
131131

132-
if (is_string || rename_rule.is_some() || rename_all_rule.is_some()) && is_int {
132+
if is_string && is_int {
133133
return Err(Error::TT(quote_spanned! {
134134
ident_span => compile_error!("All enum variants should specify the same `*_value` macro attribute, either `string_value` or `num_value` but not both");
135135
}));

sea-orm-macros/tests/derive_active_enum_test.rs

+12
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ pub enum TestEnum2 {
4646
HelloWorldTwo,
4747
}
4848

49+
#[derive(Debug, EnumIter, DeriveActiveEnum, Eq, PartialEq)]
50+
#[sea_orm(
51+
rs_type = "String",
52+
db_type = "String(StringLen::None)",
53+
rename_all = "snake_case"
54+
)]
55+
pub enum TestEnum3 {
56+
HelloWorld,
57+
}
58+
4959
#[test]
5060
fn derive_active_enum_value() {
5161
assert_eq!(TestEnum::DefaultVariant.to_value(), "defaultVariant");
@@ -124,4 +134,6 @@ fn derive_active_enum_from_value() {
124134
fn derive_active_enum_value_2() {
125135
assert_eq!(TestEnum2::HelloWorld.to_value(), "hello_world");
126136
assert_eq!(TestEnum2::HelloWorldTwo.to_value(), "helloWorldTwo");
137+
138+
assert_eq!(TestEnum3::HelloWorld.to_value(), "hello_world");
127139
}

0 commit comments

Comments
 (0)