Skip to content

Instantly share code, notes, and snippets.

@wldevries
Last active July 23, 2017 16:16
Show Gist options
  • Save wldevries/6d1b3824b26914e114cf257f0a55b963 to your computer and use it in GitHub Desktop.
Save wldevries/6d1b3824b26914e114cf257f0a55b963 to your computer and use it in GitHub Desktop.
Lifetime issues with non-copyable owned values when trying to use them after passing them to a function
enum NonCopyable {
Node ( Box<NonCopyable> ),
Leaf
}
fn do_stuff() -> NonCopyable {
let x = NonCopyable::Leaf;
match try_wrap(x) {
(val, true) => val,
(val, false) => val,
}
}
fn try_wrap(x: NonCopyable) -> (NonCopyable, bool) {
match true {
true => (NonCopyable::Node(Box::new(x)), true),
false => (x, false)
}
}
fn main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment