pub struct WasiCliNamed<T>(/* private fields */);Expand description
A helper struct which implements HasData for the wasi:cli APIs when
used in combination with named imports.
This structure is similar in purpose to WasiCli and is used
when using the named_imports module for wasi:cli. 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 WasiCliNamedView. The
corresponding Data for this type is WasiCtxNamedView which internally
will contain &mut T.
Effectively you’re going to implement WasiCliNamedView 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::cli::*;
use wasmtime_wasi::p2::bindings::named_imports;
use std::collections::HashMap;
struct MyStoreState {
table: ResourceTable,
states: HashMap<NamedId, WasiCliCtx>,
}
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::cli::environment::add_to_linker::<MyStoreState, WasiCliNamed<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 WasiCliNamedView for MyStoreState {
fn cli(&mut self, id: NamedId) -> WasiCliCtxView<'_> {
let ctx = self.states.get_mut(&id).expect("state for id");
WasiCliCtxView {
table: &mut self.table,
ctx,
}
}
}Trait Implementations§
Source§impl<T> HasData for WasiCliNamed<T>where
T: WasiCliNamedView,
impl<T> HasData for WasiCliNamed<T>where
T: WasiCliNamedView,
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 WasiCliNamed<T>where
T: WasiCliNamedView,
Available on crate feature p3 only.
impl<T, U> HostWithStore<U> for WasiCliNamed<T>where
T: WasiCliNamedView,
Available on crate feature
p3 only.Source§fn read_via_stream(
store: Access<'_, U, Self>,
id: NamedId,
) -> Result<(StreamReader<u8>, FutureReader<Result<(), ErrorCode>>)>
fn read_via_stream( store: Access<'_, U, Self>, id: NamedId, ) -> Result<(StreamReader<u8>, FutureReader<Result<(), ErrorCode>>)>
Return a stream for reading from stdin. Read more
Source§impl<T, U> HostWithStore<U> for WasiCliNamed<T>where
T: WasiCliNamedView,
Available on crate feature p3 only.
impl<T, U> HostWithStore<U> for WasiCliNamed<T>where
T: WasiCliNamedView,
Available on crate feature
p3 only.Source§fn write_via_stream(
store: Access<'_, U, Self>,
id: NamedId,
data: StreamReader<u8>,
) -> Result<FutureReader<Result<(), ErrorCode>>>
fn write_via_stream( store: Access<'_, U, Self>, id: NamedId, data: StreamReader<u8>, ) -> Result<FutureReader<Result<(), ErrorCode>>>
Write the given stream to stdout. Read more
Source§impl<T, U> HostWithStore<U> for WasiCliNamed<T>where
T: WasiCliNamedView,
Available on crate feature p3 only.
impl<T, U> HostWithStore<U> for WasiCliNamed<T>where
T: WasiCliNamedView,
Available on crate feature
p3 only.Source§fn write_via_stream(
store: Access<'_, U, Self>,
id: NamedId,
data: StreamReader<u8>,
) -> Result<FutureReader<Result<(), ErrorCode>>>
fn write_via_stream( store: Access<'_, U, Self>, id: NamedId, data: StreamReader<u8>, ) -> Result<FutureReader<Result<(), ErrorCode>>>
Write the given stream to stderr. Read more
Auto Trait Implementations§
impl<T> Freeze for WasiCliNamed<T>
impl<T> RefUnwindSafe for WasiCliNamed<T>
impl<T> Send for WasiCliNamed<T>
impl<T> Sync for WasiCliNamed<T>
impl<T> Unpin for WasiCliNamed<T>
impl<T> UnsafeUnpin for WasiCliNamed<T>
impl<T> UnwindSafe for WasiCliNamed<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