pub struct DynamicPeripherals { /* private fields */ }
Expand description
Runtime-enforced Singleton Peripheral Access
A flexible alternative to the statically checked Peripherals
, that instead verifies singleton
access to ports and peripherals at runtime, allowing you to move this struct around after taking
a port or device.
This is useful in cases where:
- You want to store unclaimed peripherals after claiming something, or pass this struct by value after
taking something from it (
Peripherals
prevents this due to partial-move rules). - Port assignments need to be configurable without recompiling.
- Port numbers need to be determined programmatically.
The system still ensures only one device can use a port at a time, but handles the
bookkeeping at runtime rather than compile time. This trades a small performance cost
for increased flexibility, but is generally preferable to use the static Peripherals
struct at runtime.
Implementations§
Source§impl DynamicPeripherals
impl DynamicPeripherals
Sourcepub fn new(peripherals: Peripherals) -> Self
pub fn new(peripherals: Peripherals) -> Self
Creates a new dynamic peripherals
In order to guarantee that no new ports are created by this struct,
this function requires a pre-existing Peripherals
instance.
This guarantees safety because Peripherals
cannot be passed by value
after it has been used to create devices.
Sourcepub const fn take_smart_port(&mut self, port_number: u8) -> Option<SmartPort>
pub const fn take_smart_port(&mut self, port_number: u8) -> Option<SmartPort>
Sourcepub const fn return_smart_port(&mut self, port: SmartPort)
pub const fn return_smart_port(&mut self, port: SmartPort)
Sourcepub const fn take_adi_port(&mut self, port_number: u8) -> Option<AdiPort>
pub const fn take_adi_port(&mut self, port_number: u8) -> Option<AdiPort>
Sourcepub const fn return_adi_port(&mut self, port: AdiPort)
pub const fn return_adi_port(&mut self, port: AdiPort)
Sourcepub const fn take_display(&mut self) -> Option<Display>
pub const fn take_display(&mut self) -> Option<Display>
Creates a Display
only if one has not been created before.
Sourcepub fn return_display(&mut self, display: Display)
pub fn return_display(&mut self, display: Display)
Returns a Display
to the dynamic peripherals.
Sourcepub const fn take_primary_controller(&mut self) -> Option<Controller>
pub const fn take_primary_controller(&mut self) -> Option<Controller>
Creates a primary controller only if one has not been created before.
Sourcepub const fn return_primary_controller(&mut self, controller: Controller)
pub const fn return_primary_controller(&mut self, controller: Controller)
Returns the primary controller to the dynamic peripherals.
Sourcepub const fn take_partner_controller(&mut self) -> Option<Controller>
pub const fn take_partner_controller(&mut self) -> Option<Controller>
Creates a partner controller only if one has not been created before.
Sourcepub const fn return_partner_controller(&mut self, controller: Controller)
pub const fn return_partner_controller(&mut self, controller: Controller)
Returns the partner controller to the dynamic peripherals.