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
impl Wire
Sourcepub fn new<S: Into<String>>(g: &mut GateGraphBuilder, name: S) -> Self
pub fn new<S: Into<String>>(g: &mut GateGraphBuilder, name: S) -> Self
Returns a new Wire with name name
.
Sourcepub fn make_lever(&mut self, g: &mut GateGraphBuilder) -> LeverHandle
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.
Sourcepub fn lever(&self) -> Option<LeverHandle>
pub fn lever(&self) -> Option<LeverHandle>
Returns Some(LeverHandle) if make_lever has been called before. None otherwise.
Sourcepub fn connect(&self, g: &mut GateGraphBuilder, other: GateIndex)
pub fn connect(&self, g: &mut GateGraphBuilder, other: GateIndex)
Connects a new GateIndex to the wire.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more