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) -> usize
pub fn append_device<B>(&mut self, device: B) -> usize
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>
pub fn replace_device<B>( &mut self, index: usize, device: B, ) -> 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>
impl<D> DynamicBus<D>
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.
Trait Implementations§
Source§impl<D: BusDevice> AsMut<[Box<dyn NamedBusDevice<<D as BusDevice>::Timestamp, Timestamp = <D as BusDevice>::Timestamp, NextDevice = NullDevice<<D as BusDevice>::Timestamp>>>]> for DynamicBus<D>
impl<D: BusDevice> AsMut<[Box<dyn NamedBusDevice<<D as BusDevice>::Timestamp, Timestamp = <D as BusDevice>::Timestamp, NextDevice = NullDevice<<D as BusDevice>::Timestamp>>>]> for DynamicBus<D>
Source§impl<D: BusDevice> AsRef<[Box<dyn NamedBusDevice<<D as BusDevice>::Timestamp, Timestamp = <D as BusDevice>::Timestamp, NextDevice = NullDevice<<D as BusDevice>::Timestamp>>>]> for DynamicBus<D>
impl<D: BusDevice> AsRef<[Box<dyn NamedBusDevice<<D as BusDevice>::Timestamp, Timestamp = <D as BusDevice>::Timestamp, NextDevice = NullDevice<<D as BusDevice>::Timestamp>>>]> for DynamicBus<D>
Source§impl<D> BusDevice for DynamicBus<D>
impl<D> BusDevice for DynamicBus<D>
Source§type NextDevice = D
type NextDevice = D
Source§fn next_device_mut(&mut self) -> &mut Self::NextDevice
fn next_device_mut(&mut self) -> &mut Self::NextDevice
Source§fn next_device_ref(&self) -> &Self::NextDevice
fn next_device_ref(&self) -> &Self::NextDevice
Source§fn into_next_device(self) -> Self::NextDevice
fn into_next_device(self) -> Self::NextDevice
Source§fn reset(&mut self, timestamp: Self::Timestamp)
fn reset(&mut self, timestamp: Self::Timestamp)
Source§fn update_timestamp(&mut self, timestamp: Self::Timestamp)
fn update_timestamp(&mut self, timestamp: Self::Timestamp)
Source§fn next_frame(&mut self, timestamp: Self::Timestamp)
fn next_frame(&mut self, timestamp: Self::Timestamp)
Source§fn read_io(
&mut self,
port: u16,
timestamp: Self::Timestamp,
) -> Option<(u8, Option<NonZeroU16>)>
fn read_io( &mut self, port: u16, timestamp: Self::Timestamp, ) -> Option<(u8, Option<NonZeroU16>)>
Source§impl<D: Default + BusDevice> Default for DynamicBus<D>
impl<D: Default + BusDevice> Default for DynamicBus<D>
Source§fn default() -> DynamicBus<D>
fn default() -> DynamicBus<D>
Source§impl<'de, D> Deserialize<'de> for DynamicBus<D>
impl<'de, D> Deserialize<'de> for DynamicBus<D>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<S, D: BusDevice> From<DynamicBus<D>> for DynamicSerdeBus<S, D>
impl<S, D: BusDevice> From<DynamicBus<D>> for DynamicSerdeBus<S, D>
Source§fn from(dynamic_bus: DynamicBus<D>) -> Self
fn from(dynamic_bus: DynamicBus<D>) -> Self
Source§impl<S, D: BusDevice> From<DynamicSerdeBus<S, D>> for DynamicBus<D>
impl<S, D: BusDevice> From<DynamicSerdeBus<S, D>> for DynamicBus<D>
Source§fn from(dynamic_bus: DynamicSerdeBus<S, D>) -> Self
fn from(dynamic_bus: DynamicSerdeBus<S, D>) -> Self
Source§impl<D: BusDevice> Index<usize> for DynamicBus<D>
impl<D: BusDevice> Index<usize> for DynamicBus<D>
Source§impl<'a, D: BusDevice> IntoIterator for &'a DynamicBus<D>
impl<'a, D: BusDevice> IntoIterator for &'a DynamicBus<D>
Source§type Item = &'a Box<dyn NamedBusDevice<<D as BusDevice>::Timestamp, Timestamp = <D as BusDevice>::Timestamp, NextDevice = NullDevice<<D as BusDevice>::Timestamp>>>
type Item = &'a Box<dyn NamedBusDevice<<D as BusDevice>::Timestamp, Timestamp = <D as BusDevice>::Timestamp, NextDevice = NullDevice<<D as BusDevice>::Timestamp>>>
Source§impl<'a, D: BusDevice> IntoIterator for &'a mut DynamicBus<D>
impl<'a, D: BusDevice> IntoIterator for &'a mut DynamicBus<D>
Source§type Item = &'a mut Box<dyn NamedBusDevice<<D as BusDevice>::Timestamp, Timestamp = <D as BusDevice>::Timestamp, NextDevice = NullDevice<<D as BusDevice>::Timestamp>>>
type Item = &'a mut Box<dyn NamedBusDevice<<D as BusDevice>::Timestamp, Timestamp = <D as BusDevice>::Timestamp, NextDevice = NullDevice<<D as BusDevice>::Timestamp>>>
Source§impl<D: BusDevice> IntoIterator for DynamicBus<D>
impl<D: BusDevice> IntoIterator for DynamicBus<D>
Source§type Item = Box<dyn NamedBusDevice<<D as BusDevice>::Timestamp, Timestamp = <D as BusDevice>::Timestamp, NextDevice = NullDevice<<D as BusDevice>::Timestamp>>>
type Item = Box<dyn NamedBusDevice<<D as BusDevice>::Timestamp, Timestamp = <D as BusDevice>::Timestamp, NextDevice = NullDevice<<D as BusDevice>::Timestamp>>>
Auto Trait Implementations§
impl<D> Freeze for DynamicBus<D>where
D: Freeze,
impl<D> !RefUnwindSafe for DynamicBus<D>
impl<D> !Send for DynamicBus<D>
impl<D> !Sync for DynamicBus<D>
impl<D> Unpin for DynamicBus<D>where
D: Unpin,
impl<D> !UnwindSafe for DynamicBus<D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<S, T> IntoSample<S> for Twhere
S: FromSample<T>,
impl<S, T> IntoSample<S> for Twhere
S: FromSample<T>,
Source§fn into_sample(self) -> S
fn into_sample(self) -> S
S a sample type from self.