return Result from OwnRef<dyn Any>::take

This commit is contained in:
numzero 2026-05-07 18:59:35 +03:00
parent 087017f9e8
commit 08c5bbd311

View File

@ -47,13 +47,13 @@ impl<T: Sized> OwnRef<'_, T> {
}
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>() {
return None;
return Err(self);
}
let p = self.0.take().unwrap();
let p = p.cast::<U>();
Some(unsafe { p.read() })
Ok(unsafe { p.read() })
}
}