Skip to main content

auric_runtime/
app.rs

1use crate::{Config, Context, data::Store, routing::Router};
2use std::sync::Arc;
3
4struct ContextImpl {
5    config: Config,
6    store: Arc<Store>,
7}
8
9pub struct App {
10    context: ContextImpl,
11}
12
13impl App {
14    pub fn new(config: Config, mut router: Router, store: Store) -> Self {
15        let store = Arc::new(store);
16        let context = ContextImpl { config, store };
17        router.init(&context).expect("failed initializing router");
18        Self { context }
19    }
20}
21
22impl Context for ContextImpl {
23    fn config(&self) -> &Config {
24        &self.config
25    }
26
27    fn store(&self) -> Arc<Store> {
28        self.store.clone()
29    }
30}
31
32impl Context for App {
33    fn config(&self) -> &Config {
34        &self.context.config
35    }
36
37    fn store(&self) -> Arc<Store> {
38        self.context.store.clone()
39    }
40}