2025-11-24 13:13:06 -07:00
|
|
|
use std::{collections::HashMap, fmt::Debug};
|
2025-11-12 17:39:11 -07:00
|
|
|
|
|
|
|
|
// use bincode::{Decode, Encode};
|
|
|
|
|
// use serde::{Deserialize, Serialize};
|
|
|
|
|
|
2025-11-14 09:43:41 -07:00
|
|
|
use bincode::{Decode, Encode};
|
|
|
|
|
|
2025-11-12 17:39:11 -07:00
|
|
|
use crate::{ModuleError, ModuleRuntime};
|
|
|
|
|
|
|
|
|
|
// /// Payload config that is instantiated
|
|
|
|
|
// #[derive(Serialize, Deserialize)]
|
|
|
|
|
// pub struct Config {
|
|
|
|
|
// pub id: String,
|
|
|
|
|
// pub key: String,
|
|
|
|
|
// pub components: Vec<String>,
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
pub struct PayloadConfig {
|
|
|
|
|
pub id: &'static str,
|
|
|
|
|
pub components: Vec<NamedComponent>,
|
|
|
|
|
pub runtime_config: Vec<RuntimeConfig>,
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-14 09:43:41 -07:00
|
|
|
#[derive(Debug, Clone, Encode, Decode)]
|
2025-11-12 17:39:11 -07:00
|
|
|
pub struct RuntimeConfig {
|
2025-11-14 09:43:41 -07:00
|
|
|
pub parent_component: String,
|
|
|
|
|
pub name: String,
|
|
|
|
|
pub config: HashMap<String, String>,
|
2025-11-12 17:39:11 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-13 11:52:01 -07:00
|
|
|
#[derive(Clone)]
|
2025-11-12 17:39:11 -07:00
|
|
|
pub struct NamedComponent {
|
|
|
|
|
pub name: &'static str,
|
|
|
|
|
|
|
|
|
|
// + Sync + Sync + Sync + Sync + Sync + Sync + Sync + Sync
|
|
|
|
|
pub get_interface: &'static (dyn Fn() -> Option<&'static (dyn InterfaceWrapper + Sync)> + Sync),
|
|
|
|
|
pub start_runtime: &'static (
|
2025-11-13 11:52:01 -07:00
|
|
|
dyn Fn(&'static RuntimeConfig) -> Result<Box<dyn ModuleRuntime>, ModuleError>
|
2025-11-12 17:39:11 -07:00
|
|
|
+ Sync
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-24 13:13:06 -07:00
|
|
|
impl Debug for NamedComponent {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
f.debug_struct("NamedComponent")
|
|
|
|
|
.field("name", &self.name)
|
|
|
|
|
// .field("get_interface", &self.get_interface)
|
|
|
|
|
// .field("start_runtime", &self.start_runtime)
|
|
|
|
|
.finish()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-12 17:39:11 -07:00
|
|
|
/// Trait that wraps the get_interface<T>() function inside of components
|
|
|
|
|
pub trait InterfaceWrapper: Send + Sync {
|
2025-11-13 11:52:01 -07:00
|
|
|
fn get_interface<T: 'static>(&self) -> Option<T>
|
2025-11-12 17:39:11 -07:00
|
|
|
where
|
|
|
|
|
Self: Sized;
|
|
|
|
|
}
|
2025-11-13 11:52:01 -07:00
|
|
|
|
|
|
|
|
// impl<T: 'static> InterfaceWrapper for T {
|
|
|
|
|
// default fn get_interface<T>() -> Option<T>
|
|
|
|
|
// where
|
|
|
|
|
// Self: Sized,
|
|
|
|
|
// {
|
|
|
|
|
// None
|
|
|
|
|
// }
|
|
|
|
|
// }
|