Struct Wire

Source
pub struct Wire {
    pub name: String,
    /* private fields */
}
Expand description

Data structure that helps with connecting wires to many different components.

It is basically syntactic sugar for an or gate.

§Example

let mut reset = Wire::new(&mut g, "reset");
let reset_lever = reset.make_lever(&mut g);
let clock = g.lever("clock");

let counter_output = counter(
    &mut g,
    clock.bit(),
    ON,  // enable
    OFF, // write
    ON,  // read
    reset.bit(),
    &zeros(4), // input
    "counter"
);
// Notice I connect the third (index 2) bit of the output to reset.
// so as soon as the counter reaches 4 (0b100) it will reset.
reset.connect(&mut g, counter_output[2]);

let output = g.output(&counter_output, "result");

let ig = &mut g.init();
ig.pulse_lever_stable(reset_lever);

assert_eq!(output.u8(ig), 0);

ig.pulse_lever_stable(clock);
assert_eq!(output.u8(ig), 1);

ig.pulse_lever_stable(clock);
assert_eq!(output.u8(ig), 2);

ig.pulse_lever_stable(clock);
assert_eq!(output.u8(ig), 3);

ig.pulse_lever_stable(clock);
assert_eq!(output.u8(ig), 0);

Fields§

§name: String

Implementations§

Source§

impl Wire

Source

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

Returns a new Wire with name name.

Source

pub fn make_lever(&mut self, g: &mut GateGraphBuilder) -> LeverHandle

Makes a new lever for the wire, stores it for easy access later and returns its LeverHandle.

Source

pub fn lever(&self) -> Option<LeverHandle>

Returns Some(LeverHandle) if make_lever has been called before. None otherwise.

Source

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

Connects a new GateIndex to the wire.

Source

pub fn bit(&self) -> GateIndex

Returns the GateIndex of the wire.

Trait Implementations§

Source§

impl Clone for Wire

Source§

fn clone(&self) -> Wire

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 Wire

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Wire

§

impl RefUnwindSafe for Wire

§

impl Send for Wire

§

impl Sync for Wire

§

impl Unpin for Wire

§

impl UnwindSafe for Wire

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.