pub struct PkHashmapVariable { /* private fields */ }Available on crate feature
std only.Expand description
A wrapper for std::collections::HashMap that implements the PkVariableAccessor trait.
This implementation provides internal mutability and a listener mechanism for variable updates.
Note: This is only available when the std feature is enabled.
Implementations§
Source§impl PkHashmapVariable
impl PkHashmapVariable
Sourcepub fn new(
init_vec: Vec<(String, Option<Vec<u8>>, Box<dyn Fn(Vec<u8>)>)>,
) -> Self
pub fn new( init_vec: Vec<(String, Option<Vec<u8>>, Box<dyn Fn(Vec<u8>)>)>, ) -> Self
Creates a new PkHashmapVariable instance.
§Arguments
init_vec: A vector of tuples, where each tuple contains:String: The variable key.Option<Vec<u8>>: The initial value of the variable. Defaults to an emptyVec<u8>ifNone.VariableChangeListener: A listener function called when the variable is set.
IMPORTANT: The listener is executed synchronously in the same thread as PkCommand::poll().
If the listener performs heavy computation, it may block the protocol state machine.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PkHashmapVariable
impl !RefUnwindSafe for PkHashmapVariable
impl !Send for PkHashmapVariable
impl !Sync for PkHashmapVariable
impl Unpin for PkHashmapVariable
impl !UnwindSafe for PkHashmapVariable
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