Component

Struct Component 

Source
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>

Source

pub fn builder() -> ComponentBuilder<Rust>

Source

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

Source

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,

Source

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:

  • input is the same length as the last sequals vector
  • all Sequal::Ends point to outputs that exist - guaranteed if constructed with ComponentBuilder and 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())
Source

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: Clone> Clone for Component<Rust>

Source§

fn clone(&self) -> Component<Rust>

Returns a duplicate 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<Rust: Debug> Debug for Component<Rust>

Source§

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

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

impl<Rust> GateLike for Component<Rust>
where Rust: GateLike,

Source§

unsafe fn compute(&mut self, input: Vec<Bit>) -> Vec<Bit>

§Safety

this function is only safe if:

  • input is the same length as the last sequals vector
  • all Sequal::Ends point to outputs that exist - guaranteed if constructed with ComponentBuilder and 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())
Source§

fn num_of_inputs(&self) -> usize

This function counts the amount of inputs a gate has Read more
Source§

fn reset(&mut self, full: bool)

This function resets the gate, if your gate needs to be reset between cpu tiks (I have no example) or between runs (for example memory)

Auto Trait Implementations§

§

impl<Rust> Freeze for Component<Rust>

§

impl<Rust> RefUnwindSafe for Component<Rust>
where Rust: RefUnwindSafe,

§

impl<Rust> Send for Component<Rust>
where Rust: Send,

§

impl<Rust> Sync for Component<Rust>
where Rust: Sync,

§

impl<Rust> Unpin for Component<Rust>
where Rust: Unpin,

§

impl<Rust> UnwindSafe for Component<Rust>
where Rust: UnwindSafe,

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.