thorpedosg

FBHdAjri

Aug 6th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. fn main() {
  2. {
  3. let x = 0;
  4. let f: Foo = x.into();
  5. let _: u32 = f.into();
  6. }
  7. }
  8.  
  9. enum Foo {
  10. Bar,
  11. Baz,
  12. }
  13.  
  14. impl From for Foo {
  15. fn from(x: u32) -> Foo {
  16. match x {
  17. 0 => Foo::Bar,
  18. 1 => Foo::Baz,
  19. _ => unreachable!(),
  20. }
  21. }
  22. }
  23.  
  24. impl Into for Foo {
  25. fn into(self) -> u32 {
  26. match self {
  27. Foo::Bar => 0,
  28. Foo::Baz => 1,
  29. }
  30. }
  31. }
Add Comment
Please, Sign In to add comment