Struct spectrusty_core::bus::DynamicBus
source · pub struct DynamicBus<D: BusDevice> { /* private fields */ }
Expand description
A pseudo bus device that allows for adding and removing devices of different types at run time.
The penalty is that the access to the devices must be done using a virtual call dispatch. Also the device of this type can’t be cloned (nor the ControlUnit with this device attached).
DynamicBus<D>
implements BusDevice itself, so obviously it’s possible to declare a statically
dispatched downstream BusDevice as its parameter D
.
Currently only types implementing BusDevice that are directly terminated with NullDevice can be attached as dynamically dispatched objects.
Implementations§
source§impl<D> DynamicBus<D>where
D: BusDevice,
impl<D> DynamicBus<D>where
D: BusDevice,
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if there are no devices in the dynamic chain. Otherwise returns false
.
sourcepub fn append_device<B>(&mut self, device: B) -> usizewhere
B: Into<BoxNamedDynDevice<D::Timestamp>>,
pub fn append_device<B>(&mut self, device: B) -> usizewhere
B: Into<BoxNamedDynDevice<D::Timestamp>>,
Appends an instance of a device
at the end of the daisy-chain.
Returns its index position in the dynamic device chain.
sourcepub fn remove_device(&mut self) -> Option<BoxNamedDynDevice<D::Timestamp>>
pub fn remove_device(&mut self) -> Option<BoxNamedDynDevice<D::Timestamp>>
Removes the last device from the dynamic daisy-chain and returns an instance of the boxed dynamic object.
sourcepub fn swap_remove_device(
&mut self,
index: usize
) -> BoxNamedDynDevice<D::Timestamp>
pub fn swap_remove_device(
&mut self,
index: usize
) -> BoxNamedDynDevice<D::Timestamp>
Replaces a device at the given index
position and returns it.
The removed device is replaced by the last device of the chain.
Panics
Panics if a device doesn’t exist at index
.
sourcepub fn replace_device<B>(
&mut self,
index: usize,
device: B
) -> BoxNamedDynDevice<D::Timestamp>where
B: Into<BoxNamedDynDevice<D::Timestamp>>,
pub fn replace_device<B>(
&mut self,
index: usize,
device: B
) -> BoxNamedDynDevice<D::Timestamp>where
B: Into<BoxNamedDynDevice<D::Timestamp>>,
Replaces a device at the given index
position. Returns the previous device occupying the replaced spot.
Panics
Panics if a device doesn’t exist at index
.
sourcepub fn get_device_ref(
&self,
index: usize
) -> Option<&NamedDynDevice<D::Timestamp>>
pub fn get_device_ref(
&self,
index: usize
) -> Option<&NamedDynDevice<D::Timestamp>>
Returns a reference to a dynamic device at index
position in the dynamic daisy-chain.
sourcepub fn get_device_mut(
&mut self,
index: usize
) -> Option<&mut NamedDynDevice<D::Timestamp>>
pub fn get_device_mut(
&mut self,
index: usize
) -> Option<&mut NamedDynDevice<D::Timestamp>>
Returns a mutable reference to a dynamic device at index
position in the dynamic daisy-chain.
source§impl<D> DynamicBus<D>where
D: BusDevice,
D::Timestamp: 'static,
impl<D> DynamicBus<D>where
D: BusDevice,
D::Timestamp: 'static,
sourcepub fn remove_as_device<B>(&mut self) -> Option<Box<B>>where
B: NamedBusDevice<D::Timestamp> + 'static,
pub fn remove_as_device<B>(&mut self) -> Option<Box<B>>where
B: NamedBusDevice<D::Timestamp> + 'static,
Removes the last device from the dynamic daisy-chain.
Panics
Panics if a device is not of a type given as parameter B
.
sourcepub fn swap_remove_as_device<B>(&mut self, index: usize) -> Box<B>where
B: NamedBusDevice<D::Timestamp> + 'static,
pub fn swap_remove_as_device<B>(&mut self, index: usize) -> Box<B>where
B: NamedBusDevice<D::Timestamp> + 'static,
Replaces a device at the given index
and returns it.
The removed device is replaced by the last device of the chain.
Panics
Panics if a device doesn’t exist at index
or if a device is not of a type given as parameter B
.
sourcepub fn as_device_ref<B>(&self, index: usize) -> &Bwhere
B: NamedBusDevice<D::Timestamp> + 'static,
pub fn as_device_ref<B>(&self, index: usize) -> &Bwhere
B: NamedBusDevice<D::Timestamp> + 'static,
Returns a reference to a device of a type B
at index
in the dynamic daisy-chain.
Panics
Panics if a device doesn’t exist at index
or if a device is not of a type given as parameter B
.
sourcepub fn as_device_mut<B>(&mut self, index: usize) -> &mut Bwhere
B: NamedBusDevice<D::Timestamp> + 'static,
pub fn as_device_mut<B>(&mut self, index: usize) -> &mut Bwhere
B: NamedBusDevice<D::Timestamp> + 'static,
Returns a mutable reference to a device of a type B
at index
in the dynamic daisy-chain.
Panics
Panics if a device doesn’t exist at index
or if a device is not of a type given as parameter B
.
sourcepub fn is_device<B>(&self, index: usize) -> boolwhere
B: NamedBusDevice<D::Timestamp> + 'static,
pub fn is_device<B>(&self, index: usize) -> boolwhere
B: NamedBusDevice<D::Timestamp> + 'static,
Returns true
if a device at index
is of a type given as parameter B
.
sourcepub fn position_device<B>(&self) -> Option<usize>where
B: NamedBusDevice<D::Timestamp> + 'static,
pub fn position_device<B>(&self) -> Option<usize>where
B: NamedBusDevice<D::Timestamp> + 'static,
Searches for a first device of a type given as parameter B
, returning its index.
sourcepub fn find_device_ref<B>(&self) -> Option<&B>where
B: NamedBusDevice<D::Timestamp> + 'static,
pub fn find_device_ref<B>(&self) -> Option<&B>where
B: NamedBusDevice<D::Timestamp> + 'static,
Searches for a first device of a type given as parameter B
, returning a reference to a device.
sourcepub fn find_device_mut<B>(&mut self) -> Option<&mut B>where
B: NamedBusDevice<D::Timestamp> + 'static,
pub fn find_device_mut<B>(&mut self) -> Option<&mut B>where
B: NamedBusDevice<D::Timestamp> + 'static,
Searches for a first device of a type given as parameter B
, returning a mutable reference to a device.