Struct machine_check::Unsigned

source ·
pub struct Unsigned<const L: u32>(/* private fields */);
Expand description

Unsigned bitvector.

The number of bits is specified in the generic parameter L. Unsigned bitvectors support bitwise operations and wrapping-arithmetic operations. Logical bit extension is also possible (any new bits are zero). Signed bitvectors be converted into Unsigned or Bitvector.

Implementations§

source§

impl<const L: u32> Unsigned<L>

source

pub fn new(value: u64) -> Self

Creates a new bitvector with the given value. Panics if the value does not fit into the type.

Examples found in repository?
examples/counter.rs (line 68)
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
        fn init(&self, input: &Input) -> State {
            State {
                value: Unsigned::<8>::new(0),
                unused: Clone::clone(&input.unused),
            }
        }

        // Machine step. Given a state and an input, the next state is generated.
        // Again, the function must be pure.
        //
        // Here, the value is incremented if input increment field is 1.
        // If it reaches 157, it is immediately reset to 0. The unused array
        // is again taken from the input, i.e. can have any values, and the
        // values do not have to match the previous ones.
        fn next(&self, state: &State, input: &Input) -> State {
            // The increment is extended to 8 bits (zero-extension because
            // it is Unsigned), then added to the value in the current state.
            // Currently, it must be called using associated function call,
            // i.e. Ext::<8>::ext(a), rather than method call input.increment.ext()
            let mut next_value = state.value + Ext::<8>::ext(input.increment);
            // If the next value is 157, it is immediately set to 0.
            if next_value == Unsigned::<8>::new(157) {
                next_value = Unsigned::<8>::new(0);
            }

            // The clone function is one of the few std functions supported
            // by machine-check. Currently, the functions can only be called
            // using associated function call, i.e. Clone::clone(&a),
            // rather than the usually used method call a.clone().
            let unused = Clone::clone(&input.unused);

            // The new state is constructed with the new value and unused fields.
            State {
                value: next_value,
                unused,
            }
        }

Trait Implementations§

source§

impl<const L: u32> Add for Unsigned<L>

§

type Output = Unsigned<L>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Unsigned<L>) -> Self::Output

Performs the + operation. Read more
source§

impl<const L: u32> BitAnd for Unsigned<L>

§

type Output = Unsigned<L>

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: Unsigned<L>) -> Self::Output

Performs the & operation. Read more
source§

impl<const L: u32> BitOr for Unsigned<L>

§

type Output = Unsigned<L>

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: Unsigned<L>) -> Self::Output

Performs the | operation. Read more
source§

impl<const L: u32> BitXor for Unsigned<L>

§

type Output = Unsigned<L>

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: Unsigned<L>) -> Self::Output

Performs the ^ operation. Read more
source§

impl<const L: u32> Clone for Unsigned<L>

source§

fn clone(&self) -> Unsigned<L>

Returns a copy 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<const L: u32> Debug for Unsigned<L>

source§

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

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

impl<const L: u32> Div for Unsigned<L>

§

type Output = Unsigned<L>

The resulting type after applying the / operator.
source§

fn div(self, rhs: Unsigned<L>) -> Self::Output

Performs the / operation. Read more
source§

impl<const L: u32, const X: u32> Ext<X> for Unsigned<L>

§

type Output = Unsigned<X>

source§

fn ext(self) -> Self::Output

source§

impl<const L: u32> From<Bitvector<L>> for Unsigned<L>

source§

fn from(value: Bitvector<L>) -> Self

Converts to this type from the input type.
source§

impl<const L: u32> From<Signed<L>> for Unsigned<L>

source§

fn from(value: Signed<L>) -> Self

Converts to this type from the input type.
source§

impl<const L: u32> From<Unsigned<L>> for Bitvector<L>

source§

fn from(value: Unsigned<L>) -> Self

Converts to this type from the input type.
source§

impl<const L: u32> From<Unsigned<L>> for Signed<L>

source§

fn from(value: Unsigned<L>) -> Self

Converts to this type from the input type.
source§

impl<const L: u32> Hash for Unsigned<L>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<const L: u32> Mul for Unsigned<L>

§

type Output = Unsigned<L>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Unsigned<L>) -> Self::Output

Performs the * operation. Read more
source§

impl<const L: u32> Not for Unsigned<L>

§

type Output = Unsigned<L>

The resulting type after applying the ! operator.
source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
source§

impl<const L: u32> Ord for Unsigned<L>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<const L: u32> PartialEq for Unsigned<L>

source§

fn eq(&self, other: &Unsigned<L>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const L: u32> PartialOrd for Unsigned<L>

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<const L: u32> Rem for Unsigned<L>

§

type Output = Unsigned<L>

The resulting type after applying the % operator.
source§

fn rem(self, rhs: Unsigned<L>) -> Self::Output

Performs the % operation. Read more
source§

impl<const L: u32> Shl for Unsigned<L>

§

type Output = Unsigned<L>

The resulting type after applying the << operator.
source§

fn shl(self, rhs: Unsigned<L>) -> Self::Output

Performs the << operation. Read more
source§

impl<const L: u32> Shr for Unsigned<L>

§

type Output = Unsigned<L>

The resulting type after applying the >> operator.
source§

fn shr(self, rhs: Unsigned<L>) -> Self::Output

Performs the >> operation. Read more
source§

impl<const L: u32> Sub for Unsigned<L>

§

type Output = Unsigned<L>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Unsigned<L>) -> Self::Output

Performs the - operation. Read more
source§

impl<const L: u32> Copy for Unsigned<L>

source§

impl<const L: u32> Eq for Unsigned<L>

source§

impl<const L: u32> StructuralPartialEq for Unsigned<L>

Auto Trait Implementations§

§

impl<const L: u32> RefUnwindSafe for Unsigned<L>

§

impl<const L: u32> Send for Unsigned<L>

§

impl<const L: u32> Sync for Unsigned<L>

§

impl<const L: u32> Unpin for Unsigned<L>

§

impl<const L: u32> UnwindSafe for Unsigned<L>

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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,

§

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

§

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

§

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.
source§

impl<N> NodeTrait for N
where N: Copy + Ord + Hash,