diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-02-03 06:36:10 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-03 06:36:10 +0100 |
| commit | a432d91d82438f4ce0f17c85b9453ae79db5390d (patch) | |
| tree | 1b398996fa42fc4d80074eb70817f3e7d218829d | |
| parent | 9af25c3396423036d0092a5f32f2d09b05a4e910 (diff) | |
PeripheralRef docs improvements.
| -rw-r--r-- | embassy-hal-common/src/peripheral.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/embassy-hal-common/src/peripheral.rs b/embassy-hal-common/src/peripheral.rs index f507468f8..4a6b6a600 100644 --- a/embassy-hal-common/src/peripheral.rs +++ b/embassy-hal-common/src/peripheral.rs | |||
| @@ -3,16 +3,17 @@ use core::ops::{Deref, DerefMut}; | |||
| 3 | 3 | ||
| 4 | /// An exclusive reference to a peripheral. | 4 | /// An exclusive reference to a peripheral. |
| 5 | /// | 5 | /// |
| 6 | /// This is functionally the same as a `&'a mut T`. The reason for having a | 6 | /// This is functionally the same as a `&'a mut T`. There's a few advantages in having |
| 7 | /// dedicated struct is memory efficiency: | 7 | /// a dedicated struct instead: |
| 8 | /// | 8 | /// |
| 9 | /// Peripheral singletons are typically either zero-sized (for concrete peripherals | 9 | /// - Memory efficiency: Peripheral singletons are typically either zero-sized (for concrete |
| 10 | /// like `PA9` or `Spi4`) or very small (for example `AnyPin` which is 1 byte). | 10 | /// peripherals like `PA9` or `SPI4`) or very small (for example `AnyPin`, which is 1 byte). |
| 11 | /// However `&mut T` is always 4 bytes for 32-bit targets, even if T is zero-sized. | 11 | /// However `&mut T` is always 4 bytes for 32-bit targets, even if T is zero-sized. |
| 12 | /// PeripheralRef stores a copy of `T` instead, so it's the same size. | 12 | /// PeripheralRef stores a copy of `T` instead, so it's the same size. |
| 13 | /// | 13 | /// - Code size efficiency. If the user uses the same driver with both `SPI4` and `&mut SPI4`, |
| 14 | /// but it is the size of `T` not the size | 14 | /// the driver code would be monomorphized two times. With PeripheralRef, the driver is generic |
| 15 | /// of a pointer. This is useful if T is a zero sized type. | 15 | /// over a lifetime only. `SPI4` becomes `PeripheralRef<'static, SPI4>`, and `&mut SPI4` becomes |
| 16 | /// `PeripheralRef<'a, SPI4>`. Lifetimes don't cause monomorphization. | ||
| 16 | pub struct PeripheralRef<'a, T> { | 17 | pub struct PeripheralRef<'a, T> { |
| 17 | inner: T, | 18 | inner: T, |
| 18 | _lifetime: PhantomData<&'a mut T>, | 19 | _lifetime: PhantomData<&'a mut T>, |
