nuit_core/
context.rs

1use std::rc::Rc;
2
3use crate::{Storage, IdPath, Id, IdPathBuf};
4
5/// A context used during rendering that tracks the path to the current view and
6/// holds a reference to internal storage.
7pub struct Context {
8    id_path: IdPathBuf,
9    storage: Rc<Storage>,
10}
11
12impl Context {
13    pub fn new(storage: Rc<Storage>) -> Self {
14        Self {
15            id_path: IdPathBuf::root(),
16            storage,
17        }
18    }
19
20    pub fn storage(&self) -> &Rc<Storage> {
21        &self.storage
22    }
23
24    pub fn id_path(&self) -> &IdPath {
25        &self.id_path
26    }
27
28    pub fn child(&self, id: impl Into<Id>) -> Self {
29        Self {
30            id_path: self.id_path.child(id),
31            storage: self.storage.clone(),
32        }
33    }
34}