From a9976fe3c96368390ac8ca1a2aec12fd4eef4ed3 Mon Sep 17 00:00:00 2001 From: Gary Guo <gary@garyguo.net> Date: Tue, 5 Oct 2021 18:43:28 +0100 Subject: [PATCH] rust: remove kernel/trait.rs `try_pin` method now lives in the `alloc` crate, so the extension trait is no longer necessary. Signed-off-by: Gary Guo <gary@garyguo.net> --- rust/kernel/lib.rs | 1 - rust/kernel/prelude.rs | 2 -- rust/kernel/traits.rs | 26 -------------------------- 3 files changed, 29 deletions(-) delete mode 100644 rust/kernel/traits.rs 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<P: Deref> { - /// Constructs a new `Pin<pointer<T>>`. 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<Pin<P>, AllocError>; -} - -impl<T> TryPin<Arc<T>> for Arc<T> { - fn try_pin(data: T) -> core::result::Result<Pin<Arc<T>>, AllocError> { - // SAFETY: the data `T` is exposed only through a `Pin<Arc<T>>`, 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)?) }) - } -}