Guest User

Untitled

a guest
Apr 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #![feature(nll)]
  2.  
  3. use std::ops::Deref;
  4.  
  5. enum Foo {
  6. A(i32),
  7. B(i32),
  8. C(i32),
  9. }
  10.  
  11. struct SBox<T> {
  12. val: T,
  13. }
  14.  
  15. impl<T> SBox<T> {
  16. pub fn new(val: T) -> Self {
  17. SBox { val }
  18. }
  19. }
  20.  
  21. impl<T> Deref for SBox<T> {
  22. type Target = T;
  23. fn deref(&self) -> &T {
  24. &self.val
  25. }
  26. }
  27.  
  28. fn foo(foo: SBox<Box<Foo>>) -> SBox<Box<Foo>> {
  29. match **foo {
  30. Foo::A(ref f) => {
  31. let f = SBox::new(Box::new(Foo::B(-f)));
  32. f
  33. }
  34. _ => foo,
  35. }
  36. }
  37.  
  38. fn main() {
  39. let mut a = SBox::new(Box::new(Foo::A(5)));
  40. a = foo(a);
  41. }
Add Comment
Please, Sign In to add comment