return Result from OwnRef<dyn Any>::take
This commit is contained in:
parent
087017f9e8
commit
08c5bbd311
|
|
@ -47,13 +47,13 @@ impl<T: Sized> OwnRef<'_, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OwnRef<'_, dyn std::any::Any> {
|
impl OwnRef<'_, dyn std::any::Any> {
|
||||||
pub fn take<U: 'static>(mut self) -> Option<U> {
|
pub fn take<U: 'static>(mut self) -> Result<U, Self> {
|
||||||
if !self.is::<U>() {
|
if !self.is::<U>() {
|
||||||
return None;
|
return Err(self);
|
||||||
}
|
}
|
||||||
let p = self.0.take().unwrap();
|
let p = self.0.take().unwrap();
|
||||||
let p = p.cast::<U>();
|
let p = p.cast::<U>();
|
||||||
Some(unsafe { p.read() })
|
Ok(unsafe { p.read() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user