-
-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DeriveDisplay macro for enum #1726
Conversation
|
||
let mut variants = Vec::new(); | ||
for variant in variant_vec { | ||
let mut display_value = "".into_token_stream(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe?
let mut display_value = TokenStream::new();
https://docs.rs/proc-macro2/latest/proc_macro2/struct.TokenStream.html
} else if meta.path.is_ident("display_value") { | ||
Some(meta.value()?.parse::<LitStr>()?); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the code for DeriveActiveEnum will panic if there is some unrecognised attributes, I added this so that deriving both Display and Active Enum would not make the code panic.
Would want some clarifying input from @tyt2y3 too. |
Hope I did not get your question wrong, but I think So the order of precedence can be: |
src/entity/active_enum.rs
Outdated
assert_eq!(format!("{}", $ident::Big), "1"); | ||
assert_eq!(format!("{}", $ident::Small), "0"); | ||
assert_eq!(format!("{}", $ident::Big), "'Big'"); | ||
assert_eq!(format!("{}", $ident::Small), "'Small'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the fallback enums doesn't pass this test as it weirdly doesn't have the single quotes
Will try to find the reason behind it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We expect no single quote:
assert_eq!(format!("{}", Enum::Big), "Big");
src/entity/active_enum.rs
Outdated
@@ -408,7 +408,7 @@ mod tests { | |||
|
|||
#[test] | |||
fn escaped_non_uax31() { | |||
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Copy)] | |||
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Copy, DeriveDisplay)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a few test cases NOT deriving DeriveDisplay where it is not needed?
Just want to make sure we have test coverage for both cases.
pub enum DisplayTea { | ||
#[sea_orm(string_value = "EverydayTea", display_value = "Everyday")] | ||
EverydayTea, | ||
#[sea_orm(string_value = "BreakfastTea", display_value = "Breakfast")] | ||
BreakfastTea, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait, actually, did I miss the test case for this? There are no corresponding asserts?
As this is the only place the display_value
attribute is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, great work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!! @darkmmon This is clean :)
🎉 Released In 0.12.1 🎉Thank you everyone for the contribution! |
PR Info
New Features
Breaking Changes
Changes