DynamicBus

Struct 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,

Source

pub fn len(&self) -> usize

Returns the number of attached devices.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no devices in the dynamic chain. Otherwise returns false.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn clear(&mut self)

Removes all dynamic devices from the dynamic daisy-chain.

Source

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.

Source

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,

Source

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.

Source

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.

Source

pub fn as_device_ref<B>(&self, index: usize) -> &B
where 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.

Source

pub fn as_device_mut<B>(&mut self, index: usize) -> &mut B
where 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.

Source

pub fn is_device<B>(&self, index: usize) -> bool
where B: NamedBusDevice<D::Timestamp> + 'static,

Returns true if a device at index is of a type given as parameter B.

Source

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.

Source

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.

Source

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>

Source§

fn as_mut(&mut self) -> &mut [BoxNamedDynDevice<D::Timestamp>]

Converts this type into a mutable reference of the (usually inferred) input type.
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>

Source§

fn as_ref(&self) -> &[BoxNamedDynDevice<D::Timestamp>]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<D> BusDevice for DynamicBus<D>
where D: BusDevice, D::Timestamp: Debug + Copy,

Source§

type Timestamp = <D as BusDevice>::Timestamp

A type used as a time-stamp.
Source§

type NextDevice = D

A type of the next device in a daisy chain.
Source§

fn next_device_mut(&mut self) -> &mut Self::NextDevice

Returns a mutable reference to the next device.
Source§

fn next_device_ref(&self) -> &Self::NextDevice

Returns a reference to the next device.
Source§

fn into_next_device(self) -> Self::NextDevice

Destructs self and returns the instance of the next bus device.
Source§

fn reset(&mut self, timestamp: Self::Timestamp)

Resets the device and all devices in this chain. Read more
Source§

fn update_timestamp(&mut self, timestamp: Self::Timestamp)

This method should be called near the end of each frame. Read more
Source§

fn next_frame(&mut self, timestamp: Self::Timestamp)

This method should be called just before the T-state counter of the control unit is wrapped when preparing for the next frame. Read more
Source§

fn read_io( &mut self, port: u16, timestamp: Self::Timestamp, ) -> Option<(u8, Option<NonZeroU16>)>

This method is called by the control unit during an I/O read cycle. Read more
Source§

fn write_io( &mut self, port: u16, data: u8, timestamp: Self::Timestamp, ) -> Option<u16>

This method is called by the control unit during an I/O write cycle. Read more
Source§

fn type_id(&self) -> TypeId
where Self: 'static,

Gets the TypeId of self. Read more
Source§

impl<D: Debug + BusDevice> Debug for DynamicBus<D>
where D::Timestamp: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<D: Default + BusDevice> Default for DynamicBus<D>
where D::Timestamp: Default,

Source§

fn default() -> DynamicBus<D>

Returns the “default value” for a type. Read more
Source§

impl<'de, D> Deserialize<'de> for DynamicBus<D>
where D: Deserialize<'de> + Default + BusDevice,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<S, D: BusDevice> From<DynamicBus<D>> for DynamicSerdeBus<S, D>

Source§

fn from(dynamic_bus: DynamicBus<D>) -> Self

Converts to this type from the input type.
Source§

impl<S, D: BusDevice> From<DynamicSerdeBus<S, D>> for DynamicBus<D>

Source§

fn from(dynamic_bus: DynamicSerdeBus<S, D>) -> Self

Converts to this type from the input type.
Source§

impl<D: BusDevice> Index<usize> for DynamicBus<D>

Source§

type Output = dyn NamedBusDevice<<D as BusDevice>::Timestamp, Timestamp = <D as BusDevice>::Timestamp, NextDevice = NullDevice<<D as BusDevice>::Timestamp>>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<D: BusDevice> IndexMut<usize> for DynamicBus<D>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

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>>>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Box<dyn NamedBusDevice<<D as BusDevice>::Timestamp, Timestamp = <D as BusDevice>::Timestamp, NextDevice = NullDevice<<D as BusDevice>::Timestamp>>>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

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>>>

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, Box<dyn NamedBusDevice<<D as BusDevice>::Timestamp, Timestamp = <D as BusDevice>::Timestamp, NextDevice = NullDevice<<D as BusDevice>::Timestamp>>>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

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>>>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Box<dyn NamedBusDevice<<D as BusDevice>::Timestamp, Timestamp = <D as BusDevice>::Timestamp, NextDevice = NullDevice<<D as BusDevice>::Timestamp>>>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<D> Serialize for DynamicBus<D>
where D: Serialize + BusDevice,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<S, T> IntoSample<S> for T
where S: FromSample<T>,

Source§

fn into_sample(self) -> S

Convert to S a sample type from self.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,