[][src]Struct logicsim::circuits::Bus

pub struct Bus { /* fields omitted */ }

Data structure that helps with managing buses, it allows you to connect &[GateIndex] to it as well as providing a &[GateIndex] to connect to other components.

It is basically syntactic sugar for a set of or gates.

Example

let input1 = constant(0x01u8);
let input2 = constant(0x10u8);

let bus = Bus::new(&mut g, 8, "bus");
bus.connect(&mut g, &input1);
bus.connect(&mut g, &input2);

let output = g.output(bus.bits(), "result");

let ig = &g.init();
assert_eq!(output.u8(ig), 0x11);

Implementations

impl Bus[src]

pub fn new<S: Into<String>>(
    g: &mut GateGraphBuilder,
    width: usize,
    name: S
) -> Self
[src]

Returns a new Bus of width width with name name.

pub fn connect(&self, g: &mut GateGraphBuilder, other: &[GateIndex])[src]

Connects a &[GateIndex] to the bus, each bit of the output of the bus will be set to the or of every corresponding bit in the inputs.

Panics

Will panic if other.len() != self.len(). Use connect_some if this is not your desired behavior.

pub fn connect_some(&self, g: &mut GateGraphBuilder, other: &[GateIndex])[src]

Connects a &[GateIndex] to the bus, each bit of the output of the bus will be set to the or of every corresponding bit in the inputs.

If there are excess bits in other, they won't get connected to the bus. If there are missing bits in other only other.len() will be connected to the bus.

pub fn merge(&self, g: &mut GateGraphBuilder, other: Bus) -> Bus[src]

Connects the bits of other to self and returns a clone of self.

pub fn len(&self) -> usize[src]

Returns the width of the bus.

pub fn is_empty(&self) -> bool[src]

Returns true if self.len() == 0.

pub fn bits(&self) -> &[GateIndex][src]

Returns a &[GateIndex] to connect to other components.

pub fn bx(&self, n: usize) -> GateIndex[src]

Returns the GateIndex of the nth bit in the bus.

Panics

Will panic if n >= self.len().

pub fn b0(&self) -> GateIndex[src]

Returns the GateIndex of the 0th bit in the bus.

Panics

Will panic if self.is_empty().

pub fn split_wires(&self, g: &mut GateGraphBuilder, other: &mut [Wire])[src]

Connects the bus to a series of Wires.

Panics

Will panic if self.len() != other.len().

Trait Implementations

impl Clone for Bus[src]

impl Debug for Bus[src]

impl Into<Vec<GateIndex, Global>> for Bus[src]

Auto Trait Implementations

impl RefUnwindSafe for Bus

impl Send for Bus

impl Sync for Bus

impl Unpin for Bus

impl UnwindSafe for Bus

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.