Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum Thing {
- V1,
- V2,
- Other(u32)
- }
- impl From<Thing> for Option<u32> {
- fn from(thing: Thing) -> Option<u32> {
- match thing {
- Thing::V1 | Thing::V2 => None,
- Thing::Other(x) => Some(x),
- }
- }
- }
- fn main() {
- let x = Thing::V1;
- let y = Thing::V2;
- let z = Thing::Other(5);
- let zz: Option<u32> = z.into();
- println!(
- "{:?}, {:?}, {:?}",
- Option::<u32>::from(x),
- Option::<u32>::from(y),
- zz
- );
- }
Add Comment
Please, Sign In to add comment