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
45
46
47
use super::{object::Objects, package::Packages, *};
use std::any::Any;
#[derive(Debug)]
pub struct MemoryBackend {
objects: Objects,
packages: Packages,
}
impl ReadBackend for MemoryBackend {
type Source = Box<dyn Any>;
fn open(_source: Self::Source) -> StoreResult<Self> {
panic!("The memory backend is just for testing cannot open")
}
fn objects(&self) -> &Objects {
&self.objects
}
fn packages(&self) -> &Packages {
&self.packages
}
}
impl WriteBackend for MemoryBackend {
type Source = Box<dyn Any>;
fn init(_source: Self::Source) -> StoreResult<Self> {
Ok(Self {
objects: Objects::new(),
packages: Packages::new(),
})
}
fn objects_mut(&mut self) -> &mut Objects {
&mut self.objects
}
fn packages_mut(&mut self) -> &mut Packages {
&mut self.packages
}
fn flush(self) -> StoreResult<()> {
Ok(())
}
}