use concinnity_core::Driver;
use concinnity_core::ecs::World;
use concinnity_core::error::WorldError;
use crate::app::runtime::Runtime;
impl Driver for Runtime {
fn start(&mut self) -> Result<(), WorldError> {
Runtime::start(self)
}
fn run(self: Box<Self>) -> Result<(), WorldError> {
(*self).run()
}
fn into_world(self: Box<Self>) -> World {
(*self).into_world()
}
fn world_mut(&mut self) -> &mut World {
Runtime::world_mut(self)
}
}
#[cfg(test)]
mod tests {
use super::*;
use concinnity_core::components::AppConfig;
#[test]
fn a_driver_starts_the_world_it_holds() {
let mut driver: Box<dyn Driver> = Box::new(Runtime::new());
assert!(driver.start().is_ok());
assert!(matches!(driver.start(), Err(WorldError::AlreadyStarted)));
}
#[test]
fn a_driver_hands_its_world_back_unrun() {
let mut runtime = Runtime::new();
runtime.world_mut().add_component(AppConfig {
home: String::new(),
max_memory_mb: 512,
job_threads: 2,
headless: false,
});
let driver: Box<dyn Driver> = Box::new(runtime);
let world = driver.into_world();
assert!(
world.query::<AppConfig>().next().is_some(),
"the world keeps its content"
);
}
}