Struct 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/timed_panic.rs (line 43)
41        fn init(&self, input: &Input) -> State {
42            State {
43                counter: Unsigned::<3>::new(0),
44                value: Unsigned::<2>::new(0),
45            }
46        }
47
48        fn next(&self, state: &State, input: &Input) -> State {
49            if state.value == Unsigned::<2>::new(3) {
50                ::std::panic!("Value must not be 3");
51            }
52
53            let next_counter = state.counter + Unsigned::<3>::new(1);
54            let mut next_value = state.value;
55            if state.counter == Unsigned::<3>::new(7) {
56                next_value = input.value;
57            }
58            State {
59                counter: next_counter,
60                value: next_value,
61            }
62        }
More examples
Hide additional examples
examples/counter.rs (line 68)
66        fn init(&self, input: &Input) -> State {
67            State {
68                value: Unsigned::<8>::new(0),
69                unused: Clone::clone(&input.unused),
70            }
71        }
72
73        // Machine step. Given a state and an input, the next state is generated.
74        // Again, the function must be pure.
75        //
76        // Here, the value is incremented if input increment field is 1.
77        // If it reaches 157, it is immediately reset to 0. The unused array
78        // is again taken from the input, i.e. can have any values, and the
79        // values do not have to match the previous ones.
80        fn next(&self, state: &State, input: &Input) -> State {
81            // The increment is extended to 8 bits (zero-extension because
82            // it is Unsigned), then added to the value in the current state.
83            // Currently, it must be called using associated function call,
84            // i.e. Ext::<8>::ext(a), rather than method call input.increment.ext()
85            let mut next_value = state.value + Ext::<8>::ext(input.increment);
86            // If the next value is 157, it is immediately set to 0.
87            if next_value == Unsigned::<8>::new(157) {
88                next_value = Unsigned::<8>::new(0);
89            }
90
91            // The clone function is one of the few std functions supported
92            // by machine-check. Currently, the functions can only be called
93            // using associated function call, i.e. Clone::clone(&a),
94            // rather than the usually used method call a.clone().
95            let unused = Clone::clone(&input.unused);
96
97            // The new state is constructed with the new value and unused fields.
98            State {
99                value: next_value,
100                unused,
101            }
102        }
examples/recovery.rs (line 66)
64        fn init(&self, _input: &Input) -> State {
65            State {
66                max_value: Unsigned::<4>::new(0),
67                unused: Bitvector::<4>::new(0),
68                free_counter: Unsigned::<4>::new(0),
69            }
70        }
71
72        fn next(&self, state: &State, input: &Input) -> State {
73            let input_value = input.value;
74
75            // If the maximum value is smaller than the input value,
76            // update it to the input value.
77            let mut next_max = state.max_value;
78            if next_max < input_value {
79                next_max = input_value;
80            }
81            // If the reset input is asserted and it is actually enabled in the system,
82            // reset the maximum value to zero.
83            if (input.reset & self.enable_reset) == Bitvector::<1>::new(1) {
84                next_max = Unsigned::<4>::new(0);
85            }
86
87            // Increment the free-running counter. It will wrap around eventually.
88            let free_counter = state.free_counter + Unsigned::<4>::new(1);
89            State {
90                max_value: next_max,
91                unused: input.unused,
92                free_counter,
93            }
94        }

Trait Implementations§

Source§

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

Source§

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>

Source§

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>

Source§

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>

Source§

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>

Source§

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>

Source§

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>

Source§

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>

Source§

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,

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

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

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

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

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>

Source§

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>

Source§

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>

Source§

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>

Source§

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> Freeze for Unsigned<L>

§

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

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

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

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,