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§

Returns the number of attached devices.

Examples found in repository?
src/bus/dynbus.rs (line 92)
91
92
93
    pub fn is_empty(&self) -> bool {
        self.len() == 0
    }

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

Appends an instance of a device at the end of the daisy-chain. Returns its index position in the dynamic device chain.

Removes the last device from the dynamic daisy-chain and returns an instance of the boxed dynamic object.

Examples found in repository?
src/bus/dynbus.rs (line 153)
150
151
152
153
154
155
156
    pub fn remove_as_device<B>(&mut self) -> Option<Box<B>>
        where B: NamedBusDevice<D::Timestamp> + 'static
    {
        self.remove_device().map(|boxdev|
            boxdev.downcast::<B>().expect("wrong dynamic device type removed")
        )
    }

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.

Examples found in repository?
src/bus/dynbus.rs (line 166)
163
164
165
166
167
    pub fn swap_remove_as_device<B>(&mut self, index: usize) -> Box<B>
        where B: NamedBusDevice<D::Timestamp> + 'static
    {
        self.swap_remove_device(index).downcast::<B>().expect("wrong dynamic device type removed")
    }

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.

Removes all dynamic devices from the dynamic daisy-chain.

Returns a reference to a dynamic device at index position in the dynamic daisy-chain.

Returns a mutable reference to a dynamic device at index position in the dynamic daisy-chain.

Removes the last device from the dynamic daisy-chain.

Panics

Panics if a device is not of a type given as parameter B.

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.

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.

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.

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

Searches for a first device of a type given as parameter B, returning its index.

Searches for a first device of a type given as parameter B, returning a reference to a device.

Searches for a first device of a type given as parameter B, returning a mutable reference to a device.

Trait Implementations§

Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
A type used as a time-stamp.
A type of the next device in a daisy chain.
Returns a mutable reference to the next device.
Returns a reference to the next device.
Destructs self and returns the instance of the next bus device.
Resets the device and all devices in this chain. Read more
This method should be called near the end of each frame. Read more
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
This method is called by the control unit during an I/O read cycle. Read more
This method is called by the control unit during an I/O write cycle. Read more
Gets the TypeId of self. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
Converts to this type from the input type.
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
Serialize this value into the given Serde serializer. Read more

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.

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.