Struct machine_check::Unsigned
source · pub struct Unsigned<const L: u32>(/* private fields */);
Expand description
Implementations§
source§impl<const L: u32> Unsigned<L>
impl<const L: u32> Unsigned<L>
sourcepub fn new(value: u64) -> Self
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> Ord for Unsigned<L>
impl<const L: u32> Ord for Unsigned<L>
source§impl<const L: u32> PartialEq for Unsigned<L>
impl<const L: u32> PartialEq for Unsigned<L>
source§impl<const L: u32> PartialOrd for Unsigned<L>
impl<const L: u32> PartialOrd for Unsigned<L>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moreimpl<const L: u32> Copy for Unsigned<L>
impl<const L: u32> Eq for Unsigned<L>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.