swim_core/
app.rs

1pub mod config;
2
3// Re-exports
4pub use config::AppConfig;
5
6use crate::{model::Model, route::Route};
7
8/// The `App` trait is implemented to divide a project into modular units referred to as `apps`.
9///
10/// An `App` is a collection of `AppConfig`, `Models` and `Routes` that are mounted at a specific path.
11pub trait App: std::fmt::Debug + Send + Sync {
12    /// Returns the mount path for this app.
13    fn mount(&self) -> &'static str;
14
15    /// Returns the config for this app.
16    fn config(&self) -> config::AppConfig;
17
18    /// Returns the models for this app.
19    fn models(&self) -> Vec<Box<dyn Model>> {
20        vec![]
21    }
22
23    /// Returns the routes for this app.
24    ///
25    /// At runtime, every request is matched against the routes of every app. The first route that matches the request is used to handle the request.
26    fn routes(&self) -> Vec<Route> {
27        vec![]
28    }
29}
30
31/// Allows an `App` to be converted into a `Box<dyn App>`.
32///
33/// Facilitates the use of the `into` method.
34impl<A: App + 'static> From<A> for Box<dyn App> {
35    fn from(app: A) -> Self {
36        Box::new(app)
37    }
38}