79561836

Date: 2025-04-08 11:01:28
Score: 3
Natty:
Report link

Thanks, everyone. At the end, I went to sleep and came back to this problem today, and solved with the strum and strum_macros crates. I marked my enum with #[derive(EnumDiscriminants, EnumString, AsRefStr)] and #[strum_discriminants(derive(EnumString, AsRefStr))], which gives me a new enum called ErrorDiscriminant that contains all the same variants but without extra data, as well as a method ErrorDiscriminant::from(&Error) that I can use to map each Error variant to an ErrorDiscriminant variant. From there, I can just do <error-discriminant> as i32 and the problem is solved.

As I'm new to Rust and this is the solution I just found, I cannot guarantee it is correct, but it's working for me so far and it makes sense.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (0.5): I cannot
  • RegEx Blacklisted phrase (1.5): I'm new
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Kaisa Azaria