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/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
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> Ord for Unsigned<L>
impl<const L: u32> Ord for Unsigned<L>
Source§impl<const L: u32> PartialOrd for Unsigned<L>
impl<const L: u32> PartialOrd for Unsigned<L>
impl<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> 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> 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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.