Skip to content

Commit

Permalink
Apply @ojeda's suggestions from code review
Browse files Browse the repository at this point in the history
This will be squashed in v2.

Co-authored-by: Miguel Ojeda <ojeda@users.noreply.github.com>
  • Loading branch information
TheSven73 and ojeda authored May 26, 2021
1 parent e451b59 commit c2811a6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions rust/kernel/traits.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// SPDX-License-Identifier: GPL-2.0

//! Traits useful to Drivers, and their implementations for common types.
//! Traits useful to drivers, and their implementations for common types.
use core::{ops::Deref, pin::Pin};

use alloc::{alloc::AllocError, sync::Arc};

/// Trait which implements a fallible version of `pin()` for any pointer type.
/// Trait which provides a fallible version of `pin()` for pointer types.
///
/// Common pointer types which implement `pin()` include `Box`, `Arc` and `Rc`.
/// Common pointer types which implement a `pin()` method include [`Box`], [`Arc`] and [`Rc`].
pub trait TryPin<P: Deref> {
/// Constructs a new Pin<pointer<T>>. If T does not implement Unpin, then data
/// 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
// 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)?) })
Expand Down

0 comments on commit c2811a6

Please sign in to comment.