pub struct StateValueList { /* private fields */ }Expand description
Stores state value records (u32) and their associated serde_json::Value payloads. Index 0 is reserved as null.
Implementations§
Source§impl StateValueList
impl StateValueList
pub fn new() -> Self
Sourcepub fn push(&mut self, key_index: u16, value: Value) -> u16
pub fn push(&mut self, key_index: u16, value: Value) -> u16
Appends a state record and its value, returning the record index.
§Examples
use state_engine::common::pool::{StateValueList, STATE_OFFSET_KEY, STATE_MASK_KEY, STATE_OFFSET_VALUE, STATE_MASK_VALUE, state_get};
use serde_json::json;
let mut list = StateValueList::new();
let idx = list.push(42, json!("hello"));
let record = list.get_record(idx).unwrap();
assert_eq!(state_get(record, STATE_OFFSET_KEY, STATE_MASK_KEY), 42);
let value = list.get_value(idx).unwrap();
assert_eq!(value, &json!("hello"));Sourcepub fn update(&mut self, index: u16, value: Value) -> bool
pub fn update(&mut self, index: u16, value: Value) -> bool
Updates the value at the given record index.
Sourcepub fn remove(&mut self, index: u16) -> bool
pub fn remove(&mut self, index: u16) -> bool
Removes a record by zeroing it (index remains valid, value becomes Null).
pub fn get_record(&self, index: u16) -> Option<StateRecord>
pub fn get_value(&self, index: u16) -> Option<&Value>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StateValueList
impl RefUnwindSafe for StateValueList
impl Send for StateValueList
impl Sync for StateValueList
impl Unpin for StateValueList
impl UnsafeUnpin for StateValueList
impl UnwindSafe for StateValueList
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