1use std::sync::Arc;
2
3use crate::Middleware;
4use crate::{Endpoint, Router};
5
6pub struct App<State> {
7 pub(crate) state: Arc<State>,
8 pub(crate) router: Router<State>,
9}
10
11pub fn new<State>(state: State) -> App<State>
13where
14 State: Send + Sync + 'static,
15{
16 App {
17 state: Arc::new(state),
18 router: Router::new(),
19 }
20}
21
22impl<State> App<State>
23where
24 State: Send + Sync + 'static,
25{
26 pub fn at(&mut self, pattern: &'static str) -> Endpoint<State> {
27 self.router.at(pattern)
28 }
29
30 pub fn include(&mut self, middleware: impl Middleware<State> + 'static) -> &mut Self {
31 self.at("/").include(middleware);
32 self
33 }
34}