1use crate::di::Container;
2
3use super::{CoreError, Module, ModuleContext, Plugin};
4
5pub struct RuestApplication {
7 pub container: Container,
8 pub port: u16,
9 pub host: String,
10 plugins: Vec<Box<dyn Plugin>>,
11}
12
13impl RuestApplication {
14 pub fn new(container: Container) -> Self {
15 Self {
16 container,
17 port: 3000,
18 host: "0.0.0.0".into(),
19 plugins: Vec::new(),
20 }
21 }
22
23 pub fn use_plugin(&mut self, plugin: impl Plugin + 'static) -> &mut Self {
24 self.plugins.push(Box::new(plugin));
25 self
26 }
27
28 pub fn set_port(&mut self, port: u16) -> &mut Self {
29 self.port = port;
30 self
31 }
32
33 pub fn set_host(&mut self, host: impl Into<String>) -> &mut Self {
34 self.host = host.into();
35 self
36 }
37
38 pub(crate) fn apply_plugins(&mut self, _ctx: &mut ModuleContext) -> Result<(), CoreError> {
39 Ok(())
40 }
41}
42
43pub fn bootstrap<M: Module>(root: M) -> Result<RuestApplication, CoreError> {
45 let container = Container::new();
46 let mut ctx = ModuleContext::new(container.clone());
47 root.configure(&mut ctx)?;
48 Ok(RuestApplication::new(ctx.container))
49}