Hey @rustlang folks! Any way of converting a c-like bitflag enum to an integer type. Doing ‘as u16’ doesn’t seem to work.
-
-
Hmm, it should work: https://rustbyexample.com/custom_types/enum/c_like.html …
1 reply 0 retweets 0 likes -
Here is my actual case, I try to do a .map(|v| v as u32) where v is of my enum type. And there i can’t seem to cast, because of ref?
1 reply 0 retweets 0 likes -
It looks like the issue if the ref. I will investigate more. Thanks for the tip!
1 reply 0 retweets 0 likes -
try |&v|
1 reply 0 retweets 0 likes -
Replying to @ozkriff
Tried that, and ‘Can’t move out borrowed value’. My current solution is to clone and cast. That seems wrong though
4 replies 0 retweets 0 likes -
Sounds like you need `#[derive(Clone, Copy)]` on the enum
1 reply 0 retweets 0 likes -
Yep, that was exactly that. I don’t really understand why they are needed though. Is it copying the value out of my iter?
1 reply 0 retweets 0 likes -
If you do `.iter`, that iterates over references to each element. To take the value out requires a copy. `.into_iter` takes ownership
1 reply 0 retweets 0 likes -
Hum. That make sense. Thank you!
1 reply 0 retweets 0 likes
Distinction really only matters for non-Copy types. Since your type is copy, it's just an extra `&` or `*`
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.