// SPDX-License-Identifier: Apache-2.0 OR MIT //! The contents of this file come from the Rust standard library, hosted in //! the repository, licensed under //! "Apache-2.0 OR MIT" and adapted for kernel use. For copyright details, //! see . use crate::sync::{arc::ArcInner, Arc}; use core::any::Any; impl Arc { /// Attempt to downcast the `Arc` to a concrete type. pub fn downcast(self) -> core::result::Result, Self> where T: Any + Send + Sync, { if (*self).is::() { // SAFETY: We have just checked that the type is correct, so we can cast the pointer. unsafe { let ptr = self.ptr.cast::>(); core::mem::forget(self); Ok(Arc::from_inner(ptr)) } } else { Err(self) } } }