Skip to main content

selium_kernel/drivers/
module_store.rs

1use std::path::PathBuf;
2
3use thiserror::Error;
4// use wasmtime::Linker;
5
6// use crate::{KernelError, registry::InstanceRegistry};
7
8pub trait ModuleStoreReadCapability {
9    fn read(&self, module_id: &str) -> Result<Vec<u8>, ModuleStoreError>;
10}
11
12// @todo Should this capability be linked?
13// pub trait ModuleStoreReadLinker: ModuleStoreReadCapability {
14//     fn link_read(&self, linker: &mut Linker<InstanceRegistry>) -> Result<(), KernelError> {
15//         todo!()
16//     }
17// }
18
19#[derive(Error, Debug)]
20pub enum ModuleStoreError {
21    #[error("Path validation failed for {0}: {1}")]
22    InvalidPath(PathBuf, String),
23    #[error("Error reading filesytem: {0}")]
24    Filesystem(String),
25}
26
27// impl<T> ModuleStoreReadLinker for T where T: ModuleStoreReadCapability + 'static {}
28
29impl From<ModuleStoreError> for i32 {
30    fn from(value: ModuleStoreError) -> Self {
31        match value {
32            ModuleStoreError::InvalidPath(_, _) => -300,
33            ModuleStoreError::Filesystem(_) => -301,
34        }
35    }
36}