1 // SPDX-License-Identifier: Apache-2.0 OR MIT
3 //! Rust standard library vendored code.
5 //! The contents of this file come from the Rust standard library, hosted in
6 //! the <https://github.com/rust-lang/rust> repository, licensed under
7 //! "Apache-2.0 OR MIT" and adapted for kernel use. For copyright details,
8 //! see <https://github.com/rust-lang/rust/blob/master/COPYRIGHT>.
10 use crate::sync::{arc::ArcInner, Arc};
13 impl Arc<dyn Any + Send + Sync> {
14 /// Attempt to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type.
15 pub fn downcast<T>(self) -> core::result::Result<Arc<T>, Self>
19 if (*self).is::<T>() {
20 // SAFETY: We have just checked that the type is correct, so we can cast the pointer.
22 let ptr = self.ptr.cast::<ArcInner<T>>();
23 core::mem::forget(self);
24 Ok(Arc::from_inner(ptr))