pub struct PkHashmapMethod { /* private fields */ }Available on crate feature
std only.Expand description
A wrapper for std::collections::HashMap that implements the PkMethodAccessor trait.
Note: This is only available when the std feature is enabled.
§Note for Method Implementation type
The type Box<dyn Fn(Option<Vec<u8>>) -> Pin<Box<dyn Pollable>>> (as appeared in the second field of the tuple that new() accepts) is a boxed closure
that takes an optional Vec<u8> as input, and returns a pinned Pollable.
This allows method implementations to perform background work and return a Pollable that becomes ready when the work is complete.
The library provides some helper types for the Pollable trait:
- Sync, based on threads:
PkPromise. - Async with Tokio:
TokioFuturePollable. - Async with Smol:
SmolFuturePollable.
And simply boxing them should work.
§Example with PkPromise
use pk_command::{PkHashmapMethod, PkPromise};
let methods = PkHashmapMethod::new(vec![(
String::from("LONGT"),
Box::new(|param| {
PkPromise::execute(|resolve| {
// do_something_with(param);
resolve(b"task complete".to_vec());
})
}),
)]);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PkHashmapMethod
impl !RefUnwindSafe for PkHashmapMethod
impl !Send for PkHashmapMethod
impl !Sync for PkHashmapMethod
impl Unpin for PkHashmapMethod
impl !UnwindSafe for PkHashmapMethod
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