pub struct State { /* private fields */ }Expand description
Data structure that represents a fixed size (at runtime) array of bits, State will keep track of when bits are updated until the next call to State::tick.
State will allocate bits in multiples of 64.
§Example
let mut s = State::new(2);
assert_eq!(s.len(), 64);
s.set(1,true);
assert_eq!(s.get_state(1), true);
assert_eq!(s.get_updated(1), true);
s.tick();
assert_eq!(s.get_state(1), true);
assert_eq!(s.get_updated(1), false);§Panics
Panics if you try to read or write to an index >= State::len()
let mut s = State::new(2);
s.get_state(64);Implementations§
Source§impl State
impl State
Sourcepub fn new(n: usize) -> State
pub fn new(n: usize) -> State
Returns a new State with n bits all of which are initialized to false.
Sourcepub fn get_updated(&self, index: usize) -> bool
pub fn get_updated(&self, index: usize) -> bool
Returns true if the bit at index has been set since the last call to State::tick.
§Panics
Panics if index >= State::len()
Sourcepub fn get_if_updated(&self, index: usize) -> Option<bool>
pub fn get_if_updated(&self, index: usize) -> Option<bool>
Returns true if the bit at index is set.
Returns None if the bit has not been set since the last call to State::tick.
§Panics
Panics if index >= State::len()
Sourcepub fn set(&mut self, index: usize, value: bool)
pub fn set(&mut self, index: usize, value: bool)
Sets the bit at index to value and keeps track that it has been updated.
§Panics
Panics if index >= State::len()
Sourcepub fn set_updated(&mut self, index: usize)
pub fn set_updated(&mut self, index: usize)
Manually marks the bit at index as updated, this is equivalent to:
s.set(0,s.get_state(0));§Panics
Panics if index >= State::len()
Sourcepub unsafe fn get_state_very_unsafely(&self, index: usize) -> bool
pub unsafe fn get_state_very_unsafely(&self, index: usize) -> bool
Unsafe version of State::get_state.
§Safety
This function is safe if index < State::len().
Will panic in debug mode if the invariant is broken.
Annoyingly long names discourage use and make you really think about what you are doing.
Sourcepub unsafe fn get_updated_very_unsafely(&self, index: usize) -> bool
pub unsafe fn get_updated_very_unsafely(&self, index: usize) -> bool
Unsafe version of State::get_updated.
§Safety
This function is safe if index < State::len().
Will panic in debug mode if the invariant is broken.
Annoyingly long names discourage use and make you really think about what you are doing.
Sourcepub unsafe fn get_if_updated_very_unsafely(&self, index: usize) -> Option<bool>
pub unsafe fn get_if_updated_very_unsafely(&self, index: usize) -> Option<bool>
Unsafe version of State::get_if_updated.
§Safety
This function is safe if index < State::len().
Will panic in debug mode if the invariant is broken.
Annoyingly long names discourage use and make you really think about what you are doing.
Sourcepub unsafe fn set_very_unsafely(&mut self, index: usize, value: bool)
pub unsafe fn set_very_unsafely(&mut self, index: usize, value: bool)
Unsafe version of State::set.
§Safety
This function is safe if index < State::len().
Will panic in debug mode if the invariant is broken.
Annoyingly long names discourage use and make you really think about what you are doing.
Trait Implementations§
Source§impl Ord for State
impl Ord for State
Source§impl PartialOrd for State
impl PartialOrd for State
impl Eq for State
impl StructuralPartialEq for State
Auto Trait Implementations§
impl Freeze for State
impl RefUnwindSafe for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnsafeUnpin for State
impl UnwindSafe for State
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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
key and return true if they are equal.