|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
2 | 2 |
|
3 | | -//! Traits useful to Drivers, and their implementations for common types. |
| 3 | +//! Traits useful to drivers, and their implementations for common types. |
4 | 4 |
|
5 | 5 | use core::{ops::Deref, pin::Pin}; |
6 | 6 |
|
7 | 7 | use alloc::{alloc::AllocError, sync::Arc}; |
8 | 8 |
|
9 | | -/// Trait which implements a fallible version of `pin()` for any pointer type. |
| 9 | +/// Trait which provides a fallible version of `pin()` for pointer types. |
10 | 10 | /// |
11 | | -/// Common pointer types which implement `pin()` include `Box`, `Arc` and `Rc`. |
| 11 | +/// Common pointer types which implement a `pin()` method include [`Box`], [`Arc`] and [`Rc`]. |
12 | 12 | pub trait TryPin<P: Deref> { |
13 | | - /// Constructs a new Pin<pointer<T>>. If T does not implement Unpin, then data |
| 13 | + /// Constructs a new `Pin<pointer<T>>`. If `T` does not implement [`Unpin`], then data |
14 | 14 | /// will be pinned in memory and unable to be moved. An error will be returned |
15 | 15 | /// if allocation fails. |
16 | 16 | fn try_pin(data: P::Target) -> core::result::Result<Pin<P>, AllocError>; |
17 | 17 | } |
18 | 18 |
|
19 | 19 | impl<T> TryPin<Arc<T>> for Arc<T> { |
20 | 20 | fn try_pin(data: T) -> core::result::Result<Pin<Arc<T>>, AllocError> { |
21 | | - // SAFETY: the data T is exposed only through a `Pin<Arc<T>>`, which |
| 21 | + // SAFETY: the data `T` is exposed only through a `Pin<Arc<T>>`, which |
22 | 22 | // does not allow data to move out of the `Arc`. Therefore it can |
23 | 23 | // never be moved. |
24 | 24 | Ok(unsafe { Pin::new_unchecked(Arc::try_new(data)?) }) |
|
0 commit comments