pub struct WasiClocksNamed<T>(/* private fields */);Expand description
A helper struct which implements HasData for the wasi:clocks APIs
when used in combination with named imports.
This structure is similar in purpose to WasiClocks and is used
when using the named_imports module for wasi:clocks. This structure
serves as the D type parameter for add_to_linker functions.
§Meaning of the T parameter
Here the T must be something that implements WasiClocksNamedView. The
corresponding Data for this type is WasiCtxNamedView which internally
will contain &mut T.
Effectively you’re going to implement WasiClocksNamedView for something in
your embedding, and that’s the T you’ll fill in here.
§Examples
use wasmtime::component::{Linker, Component, ResourceTable};
use wasmtime::{Engine, Result};
use wasmtime_wasi::{NamedId, WasiCtxNamedView};
use wasmtime_wasi::clocks::*;
use wasmtime_wasi::p2::bindings::named_imports;
use std::collections::HashMap;
struct MyStoreState {
table: ResourceTable,
states: HashMap<NamedId, WasiClocksCtx>,
}
fn main() -> Result<()> {
let engine = Engine::default();
let mut linker = Linker::new(&engine);
let component = Component::new(&engine, "(component)")?;
let mut name_map = HashMap::new();
named_imports::wasi::clocks::wall_clock::add_to_linker::<MyStoreState, WasiClocksNamed<MyStoreState>>(
&mut linker,
&component,
|name| {
let len = name_map.len();
Ok(NamedId(*name_map.entry(name.to_string()).or_insert(len)))
},
|state| WasiCtxNamedView(state),
)?;
Ok(())
}
impl WasiClocksNamedView for MyStoreState {
fn clocks(&mut self, id: NamedId) -> WasiClocksCtxView<'_> {
let ctx = self.states.get_mut(&id).expect("state for id");
WasiClocksCtxView {
table: &mut self.table,
ctx,
}
}
}Trait Implementations§
Source§impl<T> HasData for WasiClocksNamed<T>where
T: WasiClocksNamedView,
impl<T> HasData for WasiClocksNamed<T>where
T: WasiClocksNamedView,
Source§type Data<'a> = WasiCtxNamedView<'a, T>
type Data<'a> = WasiCtxNamedView<'a, T>
The data associated with this trait implementation, chiefly used as a
generic associated type to allow plumbing the
'a lifetime into the
definition here. Read moreSource§impl<T, U> HostWithStore<U> for WasiClocksNamed<T>where
T: WasiClocksNamedView,
Available on crate feature p3 only.
impl<T, U> HostWithStore<U> for WasiClocksNamed<T>where
T: WasiClocksNamedView,
Available on crate feature
p3 only.Auto Trait Implementations§
impl<T> Freeze for WasiClocksNamed<T>
impl<T> RefUnwindSafe for WasiClocksNamed<T>
impl<T> Send for WasiClocksNamed<T>
impl<T> Sync for WasiClocksNamed<T>
impl<T> Unpin for WasiClocksNamed<T>
impl<T> UnsafeUnpin for WasiClocksNamed<T>
impl<T> UnwindSafe for WasiClocksNamed<T>
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
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<H, T> HostDescriptorWithStore<T> for H
impl<H, T> HostDescriptorWithStore<T> for H
impl<H, T> HostDescriptorWithStore<T> for H
impl<H, T> HostDirectoryEntryStreamWithStore<T> for H
impl<H, T> HostDirectoryEntryStreamWithStore<T> for H
impl<H, T> HostDirectoryEntryStreamWithStore<T> for H
impl<H, T> HostErrorWithStore<T> for H
impl<H, T> HostIncomingDatagramStreamWithStore<T> for H
impl<H, T> HostIncomingDatagramStreamWithStore<T> for H
impl<H, T> HostIncomingDatagramStreamWithStore<T> for H
impl<H, T> HostInputStreamWithStore<T> for H
impl<H, T> HostInputStreamWithStore<T> for H
impl<H, T> HostNetworkWithStore<T> for H
impl<H, T> HostNetworkWithStore<T> for H
impl<H, T> HostOutgoingDatagramStreamWithStore<T> for H
impl<H, T> HostOutgoingDatagramStreamWithStore<T> for H
impl<H, T> HostOutgoingDatagramStreamWithStore<T> for H
impl<H, T> HostOutputStreamWithStore<T> for H
impl<H, T> HostOutputStreamWithStore<T> for H
impl<H, T> HostPollableWithStore<T> for H
impl<H, T> HostPollableWithStore<T> for H
impl<H, T> HostResolveAddressStreamWithStore<T> for H
impl<H, T> HostResolveAddressStreamWithStore<T> for H
impl<H, T> HostResolveAddressStreamWithStore<T> for H
impl<H, T> HostTcpSocketWithStore<T> for H
impl<H, T> HostTcpSocketWithStore<T> for H
impl<H, T> HostTcpSocketWithStore<T> for H
impl<H, T> HostTerminalInputWithStore<T> for H
impl<H, T> HostTerminalInputWithStore<T> for H
impl<H, T> HostTerminalInputWithStore<T> for H
impl<H, T> HostTerminalInputWithStore<T> for H
impl<H, T> HostTerminalOutputWithStore<T> for H
impl<H, T> HostTerminalOutputWithStore<T> for H
impl<H, T> HostTerminalOutputWithStore<T> for H
impl<H, T> HostTerminalOutputWithStore<T> for H
impl<H, T> HostUdpSocketWithStore<T> for H
impl<H, T> HostUdpSocketWithStore<T> for H
impl<H, T> HostUdpSocketWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for Hwhere
H: HasData + HostUdpSocketWithStore<T> + HostIncomingDatagramStreamWithStore<T> + HostOutgoingDatagramStreamWithStore<T> + ?Sized,
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for Hwhere
H: HasData + HostDescriptorWithStore<T> + HostDirectoryEntryStreamWithStore<T> + Send + ?Sized,
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for Hwhere
H: HasData + HostUdpSocketWithStore<T> + HostIncomingDatagramStreamWithStore<T> + HostOutgoingDatagramStreamWithStore<T> + Send + ?Sized,
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for Hwhere
H: HasData + HostDescriptorWithStore<T> + HostDirectoryEntryStreamWithStore<T> + Send + ?Sized,
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for Hwhere
H: HasData + HostUdpSocketWithStore<T> + HostIncomingDatagramStreamWithStore<T> + HostOutgoingDatagramStreamWithStore<T> + Send + ?Sized,
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
impl<H, T> HostWithStore<T> for H
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more