use wasmtime::component::Component;
use wasmtime::Engine;
pub(crate) fn instanciate_component(
engine: &Engine,
file: &String,
serialized_file: &Option<String>,
) -> anyhow::Result<Component> {
if let Some(serialized_file) = &serialized_file {
tracing::debug!("Deserializing component from serialized file: {serialized_file}");
if let Ok(bytes) = std::fs::read(serialized_file) {
match unsafe {
Component::deserialize(engine, bytes)
} {
Ok(component) => return Ok(component),
Err(e) => {
tracing::debug!(
"Failed to deserialize component from file: {serialized_file}, error: {e}"
);
}
}
}
}
tracing::debug!("Creating component from file: {file}");
Component::from_file(engine, file)
}