use crate::Error;
use wasmtime::{Config, Engine};
#[derive(Default)]
pub struct Compiler {
bytes: Vec<u8>,
}
impl Compiler {
#[must_use]
pub fn new() -> Self {
Self {
bytes: Vec::default(),
}
}
pub fn with_bytes(mut self, bytes: impl AsRef<[u8]>) -> Self {
self.bytes = bytes.as_ref().to_vec();
self
}
pub fn try_compile(self) -> Result<Vec<u8>, Error> {
let config = Config::default();
let engine = Engine::new(&config).map_err(Error::from_wasmtime)?;
engine
.precompile_module(&self.bytes)
.map_err(Error::from_wasmtime)
}
}