wasmtime_wasi/p3/sockets/host/
ip_name_lookup.rs1use crate::p3::bindings::sockets::ip_name_lookup::{ErrorCode, Host, HostWithStore};
2use crate::p3::bindings::sockets::types;
3use crate::p3::sockets::WasiSockets;
4use crate::sockets::WasiSocketsCtxView;
5use crate::sockets::ip_name_lookup::resolve_addresses;
6use wasmtime::component::Accessor;
7
8impl<U> HostWithStore<U> for WasiSockets {
9 async fn resolve_addresses(
10 store: &Accessor<U, Self>,
11 name: String,
12 ) -> wasmtime::Result<Result<Vec<types::IpAddress>, ErrorCode>> {
13 store
14 .with(|mut view| view.get().resolve_addresses(name))
15 .await
16 }
17}
18
19impl Host for WasiSocketsCtxView<'_> {}
20
21impl WasiSocketsCtxView<'_> {
22 fn resolve_addresses(
23 &self,
24 name: String,
25 ) -> impl Future<Output = wasmtime::Result<Result<Vec<types::IpAddress>, ErrorCode>>> + use<>
26 {
27 let fut = resolve_addresses(self.ctx, name);
28 async move {
29 Ok(match fut.await {
30 Ok(addrs) => Ok(addrs.into_iter().map(|addr| addr.into()).collect()),
31 Err(err) => Err(err.into()),
32 })
33 }
34 }
35}
36
37mod named {
38 use crate::p3::bindings::named_imports::wasi::sockets::ip_name_lookup::{Host, HostWithStore};
39 use crate::p3::bindings::sockets::ip_name_lookup::ErrorCode;
40 use crate::p3::bindings::sockets::types;
41 use crate::sockets::{WasiSocketsNamed, WasiSocketsNamedView};
42 use crate::{NamedId, WasiCtxNamedView};
43 use wasmtime::component::Accessor;
44
45 impl<T, U> HostWithStore<U> for WasiSocketsNamed<T>
46 where
47 T: WasiSocketsNamedView,
48 {
49 async fn resolve_addresses(
50 store: &Accessor<U, Self>,
51 id: NamedId,
52 name: String,
53 ) -> wasmtime::Result<Result<Vec<types::IpAddress>, ErrorCode>> {
54 store
55 .with(|mut view| view.get().0.sockets(id).resolve_addresses(name))
56 .await
57 }
58 }
59
60 impl<T> Host for WasiCtxNamedView<'_, T> where T: WasiSocketsNamedView {}
61}