[][src]Struct logicsim::circuits::Wire

pub struct Wire {
    pub name: String,
    // some fields omitted
}

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

impl Wire[src]

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

Returns a new Wire with name name.

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

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

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

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

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

Connects a new GateIndex to the wire.

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

Returns the GateIndex of the wire.

Trait Implementations

impl Clone for Wire[src]

impl Debug for Wire[src]

Auto Trait Implementations

impl RefUnwindSafe for Wire

impl Send for Wire

impl Sync for Wire

impl Unpin for Wire

impl UnwindSafe for Wire

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.