Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(nll)]
- use std::ops::Deref;
- enum Foo {
- A(i32),
- B(i32),
- C(i32),
- }
- struct SBox<T> {
- val: T,
- }
- impl<T> SBox<T> {
- pub fn new(val: T) -> Self {
- SBox { val }
- }
- }
- impl<T> Deref for SBox<T> {
- type Target = T;
- fn deref(&self) -> &T {
- &self.val
- }
- }
- fn foo(foo: SBox<Box<Foo>>) -> SBox<Box<Foo>> {
- match **foo {
- Foo::A(ref f) => {
- let f = SBox::new(Box::new(Foo::B(-f)));
- f
- }
- _ => foo,
- }
- }
- fn main() {
- let mut a = SBox::new(Box::new(Foo::A(5)));
- a = foo(a);
- }
Add Comment
Please, Sign In to add comment