PeripheralRef docs improvements.
This commit is contained in:
parent
9af25c3396
commit
a432d91d82
@ -3,16 +3,17 @@ use core::ops::{Deref, DerefMut};
|
|||||||
|
|
||||||
/// An exclusive reference to a peripheral.
|
/// An exclusive reference to a peripheral.
|
||||||
///
|
///
|
||||||
/// This is functionally the same as a `&'a mut T`. The reason for having a
|
/// This is functionally the same as a `&'a mut T`. There's a few advantages in having
|
||||||
/// dedicated struct is memory efficiency:
|
/// a dedicated struct instead:
|
||||||
///
|
///
|
||||||
/// Peripheral singletons are typically either zero-sized (for concrete peripherals
|
/// - Memory efficiency: Peripheral singletons are typically either zero-sized (for concrete
|
||||||
/// like `PA9` or `Spi4`) or very small (for example `AnyPin` which is 1 byte).
|
/// peripherals like `PA9` or `SPI4`) or very small (for example `AnyPin`, which is 1 byte).
|
||||||
/// However `&mut T` is always 4 bytes for 32-bit targets, even if T is zero-sized.
|
/// However `&mut T` is always 4 bytes for 32-bit targets, even if T is zero-sized.
|
||||||
/// PeripheralRef stores a copy of `T` instead, so it's the same size.
|
/// PeripheralRef stores a copy of `T` instead, so it's the same size.
|
||||||
///
|
/// - Code size efficiency. If the user uses the same driver with both `SPI4` and `&mut SPI4`,
|
||||||
/// but it is the size of `T` not the size
|
/// the driver code would be monomorphized two times. With PeripheralRef, the driver is generic
|
||||||
/// of a pointer. This is useful if T is a zero sized type.
|
/// over a lifetime only. `SPI4` becomes `PeripheralRef<'static, SPI4>`, and `&mut SPI4` becomes
|
||||||
|
/// `PeripheralRef<'a, SPI4>`. Lifetimes don't cause monomorphization.
|
||||||
pub struct PeripheralRef<'a, T> {
|
pub struct PeripheralRef<'a, T> {
|
||||||
inner: T,
|
inner: T,
|
||||||
_lifetime: PhantomData<&'a mut T>,
|
_lifetime: PhantomData<&'a mut T>,
|
||||||
|
Loading…
Reference in New Issue
Block a user