FancyBinary

Trait FancyBinary 

Source
pub trait FancyBinary: Fancy {
    // Required methods
    fn xor(&mut self, x: &Self::Item, y: &Self::Item) -> Self::Item;
    fn and(
        &mut self,
        x: &Self::Item,
        y: &Self::Item,
        channel: &mut Channel<'_>,
    ) -> Result<Self::Item>;
    fn negate(&mut self, x: &Self::Item) -> Self::Item;

    // Provided methods
    fn or(
        &mut self,
        x: &Self::Item,
        y: &Self::Item,
        channel: &mut Channel<'_>,
    ) -> Result<Self::Item> { ... }
    fn adder(
        &mut self,
        x: &Self::Item,
        y: &Self::Item,
        carry_in: Option<&Self::Item>,
        channel: &mut Channel<'_>,
    ) -> Result<(Self::Item, Self::Item)> { ... }
    fn and_many(
        &mut self,
        args: &[Self::Item],
        channel: &mut Channel<'_>,
    ) -> Result<Self::Item> { ... }
    fn or_many(
        &mut self,
        args: &[Self::Item],
        channel: &mut Channel<'_>,
    ) -> Result<Self::Item> { ... }
    fn xor_many(&mut self, args: &[Self::Item]) -> Self::Item { ... }
    fn mux_constant_bits(
        &mut self,
        x: &Self::Item,
        b1: bool,
        b2: bool,
        channel: &mut Channel<'_>,
    ) -> Result<Self::Item> { ... }
    fn mux(
        &mut self,
        b: &Self::Item,
        x: &Self::Item,
        y: &Self::Item,
        channel: &mut Channel<'_>,
    ) -> Result<Self::Item> { ... }
}
Expand description

Fancy DSL providing binary operations

Required Methods§

Source

fn xor(&mut self, x: &Self::Item, y: &Self::Item) -> Self::Item

Binary Xor

Source

fn and( &mut self, x: &Self::Item, y: &Self::Item, channel: &mut Channel<'_>, ) -> Result<Self::Item>

Binary And

Source

fn negate(&mut self, x: &Self::Item) -> Self::Item

Binary Not

Provided Methods§

Source

fn or( &mut self, x: &Self::Item, y: &Self::Item, channel: &mut Channel<'_>, ) -> Result<Self::Item>

Uses Demorgan’s Rule implemented with an and gate and negation.

Source

fn adder( &mut self, x: &Self::Item, y: &Self::Item, carry_in: Option<&Self::Item>, channel: &mut Channel<'_>, ) -> Result<(Self::Item, Self::Item)>

Binary adder. Returns the result and the carry.

Source

fn and_many( &mut self, args: &[Self::Item], channel: &mut Channel<'_>, ) -> Result<Self::Item>

Returns 1 if all wires equal 1.

§Panics

Panics if args is empty.

Source

fn or_many( &mut self, args: &[Self::Item], channel: &mut Channel<'_>, ) -> Result<Self::Item>

Returns 1 if any wire equals 1.

§Panics

Panics if args is empty.

Source

fn xor_many(&mut self, args: &[Self::Item]) -> Self::Item

XOR many wires together.

§Panics

Panics if args.len() < 2.

Source

fn mux_constant_bits( &mut self, x: &Self::Item, b1: bool, b2: bool, channel: &mut Channel<'_>, ) -> Result<Self::Item>

If x = 0 returns the constant b1 else return b2. Folds constants if possible.

Source

fn mux( &mut self, b: &Self::Item, x: &Self::Item, y: &Self::Item, channel: &mut Channel<'_>, ) -> Result<Self::Item>

If b = 0 returns x else y.

Implementors§