pub trait PkMethodAccessor {
// Required method
fn call(
&self,
key: String,
param: Vec<u8>,
) -> Result<Pin<Box<dyn Pollable>>, String>;
}Expand description
Trait defining how to invoke methods by their string key.
This allows the PkCommand state machine to call arbitrary logic on the device.
In std environments, a convenient implementation using std::collections::HashMap is provided as PkHashmapMethod.
In no_std environments, you must provide your own implementation.
§Example
use pk_command::{PkMethodAccessor, Pollable};
use std::pin::Pin;
use std::task::Poll;
struct MyMethod;
impl Pollable for MyMethod {
fn poll(&self) -> Poll<Result<Option<Vec<u8>>, String>> {
Poll::Ready(Ok(Some(b"Hello from PK!".to_vec())))
}
}
struct MyMethodStore;
impl PkMethodAccessor for MyMethodStore {
fn call(&self, key: String, param: Vec<u8>) -> Result<Pin<Box<dyn Pollable>>, String> {
if key == "GREET" {
Ok(Box::pin(MyMethod))
} else {
Err("Method not found".to_string())
}
}
}Required Methods§
Implementors§
impl PkMethodAccessor for PkHashmapMethod
Available on crate feature
std only.