1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
mod host_functions;
#[cfg(feature = "wasm3")]
mod wasm3;
#[cfg(feature = "wasmer")]
mod wasmer;
use std::sync::Arc;
use anyhow::Error;
#[cfg(feature = "wasm3")]
pub(crate) use self::wasm3::Wasm3Engine;
#[cfg(feature = "wasmer")]
pub(crate) use self::wasmer::WasmerEngine;
pub(crate) trait WebAssemblyEngine {
fn load(
wasm: &[u8],
callbacks: Arc<dyn crate::callbacks::Callbacks>,
) -> Result<Self, LoadError>
where
Self: Sized;
fn init(&mut self) -> Result<(), Error>;
fn predict(&mut self) -> Result<(), Error>;
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum LoadError {
#[error(transparent)]
Other(#[from] anyhow::Error),
#[error(transparent)]
#[cfg(feature = "wasmer")]
WasmerInstantiation(#[from] ::wasmer::InstantiationError),
#[error(transparent)]
#[cfg(feature = "wasmer")]
WasmerCompile(#[from] ::wasmer::CompileError),
}