1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::sync::Arc;
use crate::{io::FileManager, vault::AnyVault, ChunkCache, Vault};
#[derive(Default, Debug, Clone)]
#[must_use]
pub struct Context<M: FileManager> {
pub file_manager: M,
pub(crate) vault: Option<Arc<dyn AnyVault>>,
pub(crate) cache: Option<ChunkCache>,
}
impl<M: FileManager> Context<M> {
pub fn vault(&self) -> Option<&dyn AnyVault> {
self.vault.as_deref()
}
pub fn cache(&self) -> Option<&ChunkCache> {
self.cache.as_ref()
}
pub fn with_cache(mut self, cache: ChunkCache) -> Self {
self.cache = Some(cache);
self
}
pub fn with_vault<V: Vault>(self, vault: V) -> Self {
self.with_any_vault(Arc::new(vault))
}
pub fn with_any_vault(mut self, vault: Arc<dyn AnyVault>) -> Self {
self.vault = Some(vault);
self
}
}