use uuid::Uuid;
use crate::engine::{Engine, LoadModuleError};
use crate::schema::module::low::{Header, ModuleDefinition};
#[derive(Debug, Clone)]
pub struct LoadedModule {
pub id: Uuid,
pub function_ids: Vec<Uuid>,
}
pub fn module_definition_from_parts(header: Header, executable: Box<[u8]>) -> ModuleDefinition {
ModuleDefinition {
schema_version: 0,
header,
executable,
}
}
pub fn load_module_from_parts(
engine: &mut Engine,
header: Header,
executable: Box<[u8]>,
) -> Result<LoadedModule, LoadModuleError> {
let id = header.id;
let function_ids = header.exports.iter().map(|e| *e.id()).collect();
engine.load_module(module_definition_from_parts(header, executable))?;
Ok(LoadedModule { id, function_ids })
}