pub struct WasiSocketsNamed<T>(/* private fields */);Expand description
A helper struct which implements HasData for the wasi:sockets APIs
when used in combination with named imports.
This structure is similar in purpose to WasiSockets and is used
when using the named_imports module for wasi:sockets. 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 WasiSocketsNamedView. The
corresponding Data for this type is WasiCtxNamedView which internally
will contain &mut T.
Effectively you’re going to implement WasiSocketsNamedView 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::sockets::*;
use wasmtime_wasi::p2::bindings::named_imports;
use std::collections::HashMap;
struct MyStoreState {
table: ResourceTable,
states: HashMap<NamedId, WasiSocketsCtx>,
}
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::sockets::instance_network::add_to_linker::<MyStoreState, WasiSocketsNamed<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 WasiSocketsNamedView for MyStoreState {
fn sockets(&mut self, id: NamedId) -> WasiSocketsCtxView<'_> {
let ctx = self.states.get_mut(&id).expect("state for id");
WasiSocketsCtxView {
table: &mut self.table,
ctx,
}
}
}Trait Implementations§
Source§impl<T> HasData for WasiSocketsNamed<T>where
T: WasiSocketsNamedView,
impl<T> HasData for WasiSocketsNamed<T>where
T: WasiSocketsNamedView,
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> HostTcpSocketWithStore<U> for WasiSocketsNamed<T>where
T: WasiSocketsNamedView,
U: Send,
Available on crate feature p3 only.
impl<T, U> HostTcpSocketWithStore<U> for WasiSocketsNamed<T>where
T: WasiSocketsNamedView,
U: Send,
Available on crate feature
p3 only.Source§async fn connect(
store: &Accessor<U, Self>,
id: NamedId,
socket: Resource<TcpSocket>,
remote_address: IpSocketAddress,
) -> SocketResult<()>
async fn connect( store: &Accessor<U, Self>, id: NamedId, socket: Resource<TcpSocket>, remote_address: IpSocketAddress, ) -> SocketResult<()>
Connect to a remote endpoint. Read more
Source§async fn listen(
store: Access<'_, U, Self>,
id: NamedId,
socket_resource: Resource<TcpSocket>,
) -> SocketResult<StreamReader<Resource<TcpSocket>>>
async fn listen( store: Access<'_, U, Self>, id: NamedId, socket_resource: Resource<TcpSocket>, ) -> SocketResult<StreamReader<Resource<TcpSocket>>>
Start listening and return a stream of new inbound connections. Read more
Source§impl<T, U> HostUdpSocketWithStore<U> for WasiSocketsNamed<T>where
T: WasiSocketsNamedView,
Available on crate feature p3 only.
impl<T, U> HostUdpSocketWithStore<U> for WasiSocketsNamed<T>where
T: WasiSocketsNamedView,
Available on crate feature
p3 only.Source§impl<T, U> HostWithStore<U> for WasiSocketsNamed<T>where
T: WasiSocketsNamedView,
Available on crate feature p3 only.
impl<T, U> HostWithStore<U> for WasiSocketsNamed<T>where
T: WasiSocketsNamedView,
Available on crate feature
p3 only.Auto Trait Implementations§
impl<T> Freeze for WasiSocketsNamed<T>
impl<T> RefUnwindSafe for WasiSocketsNamed<T>
impl<T> Send for WasiSocketsNamed<T>
impl<T> Sync for WasiSocketsNamed<T>
impl<T> Unpin for WasiSocketsNamed<T>
impl<T> UnsafeUnpin for WasiSocketsNamed<T>
impl<T> UnwindSafe for WasiSocketsNamed<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 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 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<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