Here how to fix this code? Playground
fn main() {
let mut option = MyOption::MySome(String::new());
option.take();
}
enum MyOption<T> {
MyNone,
MySome(T),
}
impl<T> MyOption<T> {
fn take(&mut self) -> Option<T> {
match self {
MyOption::MySome(value) => {
*self = MyOption::MyNone;
Some(value)
},
MyOption::MyNone => None,
}
}
}