pub trait PkVariableAccessor {
// Required methods
fn get(&self, key: String) -> Option<Vec<u8>>;
fn set(&self, key: String, value: Vec<u8>) -> Result<(), String>;
}Expand description
Trait defining how to access (get/set) variables by their string key.
This allows the PkCommand state machine to be generic over the actual variable storage.
In std environments, a convenient implementation using std::collections::HashMap is provided as PkHashmapVariable.
In no_std environments, you must provide your own implementation.
§Example
use pk_command::PkVariableAccessor;
struct MyVariableStore;
impl PkVariableAccessor for MyVariableStore {
fn get(&self, key: String) -> Option<Vec<u8>> {
if key == "VERSION" {
Some(b"1.0.0".to_vec())
} else {
None
}
}
fn set(&self, key: String, value: Vec<u8>) -> Result<(), String> {
// Logic to store the value
Ok(())
}
}Required Methods§
Implementors§
impl PkVariableAccessor for PkHashmapVariable
Available on crate feature
std only.