pub struct Component<Rust = Infallible> { /* private fields */ }Expand description
A circuit
use builder() to construct
use compute to run the logic
stick inside a Gate::component to use as part of a bigger component and
compose with other gates
put a gate implemented in rust (or an enum of them) in <Rust> to use it
(or them)
Implementations§
Source§impl<Rust> Component<Rust>
impl<Rust> Component<Rust>
Sourcepub fn builder() -> ComponentBuilder<Rust>
pub fn builder() -> ComponentBuilder<Rust>
Aquire a ComponentBuilder
Sourcepub fn single_gate(gate: Gate<Rust>, num_of_outputs: usize) -> Self
pub fn single_gate(gate: Gate<Rust>, num_of_outputs: usize) -> Self
Create a component out of a single gate
this is mostly useless since the gate itself can probably do whatever you need and exists mostly for tests
Sourcepub fn from_raw_parts(
gates: Vec<Gate<Rust>>,
sequals: Vec<Vec<Sequal>>,
outputs: usize,
) -> Self
pub fn from_raw_parts( gates: Vec<Gate<Rust>>, sequals: Vec<Vec<Sequal>>, outputs: usize, ) -> Self
Create a component from it’s raw parts
in sequals each Vec<Sequal> corresponds to a single gates sequals
(in the same index) and the last corresponds to the components inputs
outputs is the amount of outputs your component has
Source§impl<Rust> Component<Rust>where
Rust: GateLike,
impl<Rust> Component<Rust>where
Rust: GateLike,
Sourcepub unsafe fn run(&mut self, input: Vec<Bit>) -> Vec<Bit> ⓘ
pub unsafe fn run(&mut self, input: Vec<Bit>) -> Vec<Bit> ⓘ
Runs the component
This is an alias for compute since that function
is inside a trait impl and thus way harder to find, also the name is
nice
§Safety
this function is only safe if:
inputis the same length as the last sequals vector- all
Sequal::Ends point to outputs that exist - guaranteed if constructed withComponentBuilderand used outputs from 0 up to the number of outputs - all
Sequal::Gates must point to actual inputs of actual gates - component is clean (right after construction or after a call to
Component::reset())
Sourcepub fn reset(&mut self, full_reset: bool)
pub fn reset(&mut self, full_reset: bool)
Resets the whole component
this must be done in between cpu ticks (calls to compute) in order for the gates to work (otherwise the code is panicks in debug and is unsound in release)
a full reset is done in between runs, this is to reset things like memory that are kept between ticks
Trait Implementations§
Source§impl<Rust> GateLike for Component<Rust>where
Rust: GateLike,
impl<Rust> GateLike for Component<Rust>where
Rust: GateLike,
Source§unsafe fn compute(&mut self, input: Vec<Bit>) -> Vec<Bit> ⓘ
unsafe fn compute(&mut self, input: Vec<Bit>) -> Vec<Bit> ⓘ
§Safety
this function is only safe if:
inputis the same length as the last sequals vector- all
Sequal::Ends point to outputs that exist - guaranteed if constructed withComponentBuilderand used outputs from 0 up to the number of outputs - all
Sequal::Gates must point to actual inputs of actual gates - component is clean (right after construction or after a call to
Component::reset())