From e81d4cea03142eca99ae656928d1ac8f9615c2e9 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 7 Mar 2022 22:17:59 +0100 Subject: [PATCH] feat(wasi): make `WasiCtx` overridable (#3895) In some use cases it is desirable to provide a custom snapshot WASI context. Facilitate this by depending on a combination of traits required rather than concrete type in the signature. Signed-off-by: Roman Volosatovs --- crates/wasi/src/lib.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/wasi/src/lib.rs b/crates/wasi/src/lib.rs index 91fd9b6c3d9f..17744239783b 100644 --- a/crates/wasi/src/lib.rs +++ b/crates/wasi/src/lib.rs @@ -42,11 +42,16 @@ macro_rules! define_wasi { use wasmtime::Linker; -pub fn add_to_linker( +pub fn add_to_linker( linker: &mut Linker, - get_cx: impl Fn(&mut T) -> &mut crate::WasiCtx + Send + Sync + Copy + 'static, + get_cx: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, ) -> anyhow::Result<()> - where $($bounds)* + where U: Send + + wasi_common::snapshots::preview_0::wasi_unstable::WasiUnstable + + wasi_common::snapshots::preview_0::types::UserErrorConversion + + wasi_common::snapshots::preview_1::wasi_snapshot_preview1::WasiSnapshotPreview1 + + wasi_common::snapshots::preview_1::types::UserErrorConversion, + $($bounds)* { snapshots::preview_1::add_wasi_snapshot_preview1_to_linker(linker, get_cx)?; snapshots::preview_0::add_wasi_unstable_to_linker(linker, get_cx)?;