Embassy
embassy-stm32

Crates

git

Versions

stm32f030c6

Flavors

pub struct PeripheralRef<'a, T> { /* private fields */ }
Expand description

An exclusive reference to a peripheral.

This is functionally the same as a &'a mut T. The reason for having a dedicated struct is memory efficiency:

Peripheral singletons are typically either zero-sized (for concrete peripehrals 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. PeripheralRef stores a copy of T instead, so it’s the same size.

but it is the size of T not the size of a pointer. This is useful if T is a zero sized type.

Implementations

Unsafely clone (duplicate) a peripheral singleton.

Safety

This returns an owned clone of the peripheral. You must manually ensure only one copy of the peripheral is in use at a time. For example, don’t create two SPI drivers on SPI1, because they will “fight” each other.

You should strongly prefer using reborrow() instead. It returns a PeripheralRef that borrows self, which allows the borrow checker to enforce this at compile time.

Reborrow into a “child” PeripheralRef.

self will stay borrowed until the child PeripheralRef is dropped.

Map the inner peripheral using Into.

This converts from PeripheralRef<'a, T> to PeripheralRef<'a, U>, using an Into impl to convert from T to U.

For example, this can be useful to degrade GPIO pins: converting from PeripheralRef<’a, PB11>toPeripheralRef<’a, AnyPin>`.

Trait Implementations

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Peripheral singleton type

Unsafely clone (duplicate) a peripheral singleton. Read more

Convert a value into a PeripheralRef. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.