Struct Bus

Source
pub struct Bus { /* private fields */ }
Expand description

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§

Source§

impl Bus

Source

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

Returns a new Bus of width width with name name.

Source

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

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.

Source

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

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.

Source

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

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

Source

pub fn len(&self) -> usize

Returns the width of the bus.

Source

pub fn is_empty(&self) -> bool

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

Source

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

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

Source

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

Returns the GateIndex of the nth bit in the bus.

§Panics

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

Source

pub fn b0(&self) -> GateIndex

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

§Panics

Will panic if self.is_empty().

Source

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

Connects the bus to a series of Wires.

§Panics

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

Trait Implementations§

Source§

impl Clone for Bus

Source§

fn clone(&self) -> Bus

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Bus

Source§

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

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

impl Into<Vec<GateIndex>> for Bus

Source§

fn into(self) -> Vec<GateIndex>

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

§

impl Freeze for Bus

§

impl RefUnwindSafe for Bus

§

impl Send for Bus

§

impl Sync for Bus

§

impl Unpin for Bus

§

impl UnwindSafe for Bus

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.