Created
May 29, 2019 02:53
-
-
Save dsp/bdb694019e42eeaa0dc4c41309e2b20a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub enum Owned<T> { | |
Empty, | |
Mine(T), | |
} | |
impl<T> Owned<T> { | |
pub fn take(&mut self) -> T { | |
match std::mem::replace(self, Owned::Empty) { | |
Owned::Mine(t) => t, | |
Owned::Empty => panic!("Can't call take on Empty"), | |
} | |
} | |
pub fn as_ref(&self) -> &T { | |
match self { | |
Owned::Empty => panic!("Can't call as_ref on Empty"), | |
Owned::Mine(t) => &t, | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment