use std::any::Any; pub(crate) trait ValueBoxContainer { fn replace_value(&mut self, object: T) -> Option; fn take_value(&mut self) -> Option; fn clone_value(&self) -> Option where T: Clone; fn has_value(&self) -> bool; } impl ValueBoxContainer for Option> { fn replace_value(&mut self, object: T) -> Option { self.replace(Box::new(object)).map(|boxed| *boxed) } fn take_value(&mut self) -> Option { self.take().map(|boxed| *boxed) } fn clone_value(&self) -> Option where T: Clone, { Clone::clone(self).map(|boxed| *boxed) } fn has_value(&self) -> bool { self.is_some() } }