wasmer_engine_universal_artifact/
engine.rsuse loupe::MemoryUsage;
use wasmer_compiler::CompileError;
use wasmer_compiler::Compiler;
use wasmer_types::Features;
#[derive(MemoryUsage)]
pub struct UniversalEngineBuilder {
#[cfg(feature = "compiler")]
compiler: Option<Box<dyn Compiler>>,
features: Features,
}
impl UniversalEngineBuilder {
#[cfg(feature = "compiler")]
pub fn new(compiler: Option<Box<dyn Compiler>>, features: Features) -> Self {
UniversalEngineBuilder { compiler, features }
}
#[cfg(feature = "compiler")]
pub fn compiler(&self) -> Result<&dyn Compiler, CompileError> {
if self.compiler.is_none() {
return Err(CompileError::Codegen(
"The UniversalEngine is not compiled in.".to_string(),
));
}
Ok(&**self.compiler.as_ref().unwrap())
}
#[cfg(not(feature = "compiler"))]
pub fn compiler(&self) -> Result<&dyn Compiler, CompileError> {
return Err(CompileError::Codegen(
"The UniversalEngine is not compiled in.".to_string(),
));
}
#[cfg(feature = "compiler")]
pub fn validate<'data>(&self, data: &'data [u8]) -> Result<(), CompileError> {
self.compiler()?.validate_module(self.features(), data)
}
#[cfg(not(feature = "compiler"))]
pub fn validate<'data>(&self, _data: &'data [u8]) -> Result<(), CompileError> {
Err(CompileError::Validate(
"The UniversalEngine is not compiled with compiler support, which is required for validating"
.to_string(),
))
}
pub fn features(&self) -> &Features {
&self.features
}
}