Skip to main content

ruest/core/
factory.rs

1use super::{bootstrap, CoreError, Module, RuestApplication};
2
3/// Factory for creating RUEST applications (NestJS-style).
4pub struct RuestFactory;
5
6impl RuestFactory {
7    /// Create and bootstrap an application from the root module.
8    pub fn create<M: Module>(root: M) -> Result<ApplicationBuilder, CoreError> {
9        let app = bootstrap(root)?;
10        Ok(ApplicationBuilder { app })
11    }
12}
13
14/// Fluent builder after module bootstrap.
15pub struct ApplicationBuilder {
16    app: RuestApplication,
17}
18
19impl ApplicationBuilder {
20    pub fn port(mut self, port: u16) -> Self {
21        self.app.set_port(port);
22        self
23    }
24
25    pub fn host(mut self, host: impl Into<String>) -> Self {
26        self.app.set_host(host);
27        self
28    }
29
30    pub fn build(self) -> RuestApplication {
31        self.app
32    }
33}