mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-10-23 07:34:24 +02:00

Steps on the way to 6.12.18 Resolves merge conflicts in: rust/kernel/types.rs scripts/Makefile.build Change-Id: I1a0d7a30074e2532f53b9c9d4cf0e8346d57ffef Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> [Re-resolved rust/kernel/types.rs <mmaurer@google.com>] Signed-off-by: Matthew Maurer <mmaurer@google.com>
31 lines
1.0 KiB
Rust
31 lines
1.0 KiB
Rust
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
|
|
//! Rust standard library vendored code.
|
|
//!
|
|
//! The contents of this file come from the Rust standard library, hosted in
|
|
//! the <https://github.com/rust-lang/rust> repository, licensed under
|
|
//! "Apache-2.0 OR MIT" and adapted for kernel use. For copyright details,
|
|
//! see <https://github.com/rust-lang/rust/blob/master/COPYRIGHT>.
|
|
|
|
use crate::sync::{arc::ArcInner, Arc};
|
|
use core::any::Any;
|
|
|
|
impl Arc<dyn Any + Send + Sync> {
|
|
/// Attempt to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type.
|
|
pub fn downcast<T>(self) -> core::result::Result<Arc<T>, Self>
|
|
where
|
|
T: Any + Send + Sync,
|
|
{
|
|
if (*self).is::<T>() {
|
|
// SAFETY: We have just checked that the type is correct, so we can cast the pointer.
|
|
unsafe {
|
|
let ptr = self.ptr.cast::<ArcInner<T>>();
|
|
core::mem::forget(self);
|
|
Ok(Arc::from_inner(ptr))
|
|
}
|
|
} else {
|
|
Err(self)
|
|
}
|
|
}
|
|
}
|