Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- {
- let x = 0;
- let f: Foo = x.into();
- let _: u32 = f.into();
- }
- }
- enum Foo {
- Bar,
- Baz,
- }
- impl From for Foo {
- fn from(x: u32) -> Foo {
- match x {
- 0 => Foo::Bar,
- 1 => Foo::Baz,
- _ => unreachable!(),
- }
- }
- }
- impl Into for Foo {
- fn into(self) -> u32 {
- match self {
- Foo::Bar => 0,
- Foo::Baz => 1,
- }
- }
- }
Add Comment
Please, Sign In to add comment