diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index df5b8629fe0f9d..2c98e08ed29e38 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -54,7 +54,6 @@ pub mod power; pub mod security; pub mod str; pub mod task; -pub mod traits; pub mod linked_list; mod raw_list; diff --git a/rust/kernel/prelude.rs b/rust/kernel/prelude.rs index dbbf49be4bd9ec..34d9cc8a82d45f 100644 --- a/rust/kernel/prelude.rs +++ b/rust/kernel/prelude.rs @@ -24,5 +24,3 @@ pub use super::{pr_alert, pr_crit, pr_debug, pr_emerg, pr_err, pr_info, pr_notic pub use super::static_assert; pub use super::{Error, KernelModule, Result}; - -pub use crate::traits::TryPin; diff --git a/rust/kernel/traits.rs b/rust/kernel/traits.rs deleted file mode 100644 index 39a43169bf70e6..00000000000000 --- a/rust/kernel/traits.rs +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -//! Traits useful to drivers, and their implementations for common types. - -use core::{ops::Deref, pin::Pin}; - -use alloc::{alloc::AllocError, sync::Arc}; - -/// Trait which provides a fallible version of `pin()` for pointer types. -/// -/// Common pointer types which implement a `pin()` method include [`Box`](alloc::boxed::Box) and [`Arc`]. -pub trait TryPin { - /// Constructs a new `Pin>`. If `T` does not implement [`Unpin`], then data - /// will be pinned in memory and unable to be moved. An error will be returned - /// if allocation fails. - fn try_pin(data: P::Target) -> core::result::Result, AllocError>; -} - -impl TryPin> for Arc { - fn try_pin(data: T) -> core::result::Result>, AllocError> { - // SAFETY: the data `T` is exposed only through a `Pin>`, which - // does not allow data to move out of the `Arc`. Therefore it can - // never be moved. - Ok(unsafe { Pin::new_unchecked(Arc::try_new(data)?) }) - } -}