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
48
49
50
51
52
53
54
55
56
57
58
59
extern crate shelf;
use std::collections::HashMap;
use shelf::Shelf;
pub struct Desk {
desk: HashMap<String, String>,
shelf: Shelf
}
impl Desk {
pub fn new(path: Option<&str>) -> Desk {
let desk = HashMap::new();
let shelf = match path {
Some(path) => Shelf::new(path),
None => Shelf::new("/tmp/shelf")
};
Desk {
desk: desk,
shelf: shelf
}
}
pub fn set(&mut self, key: &str, value: &str) -> () {
let prev = self.desk.insert(key.to_string(), value.to_string());
if self.shelf.get(key) != prev {
self.shelf.set(key, value);
}
}
pub fn get(&self, key: &str) -> Option<String> {
match self.desk.get(key) {
Some(value) => Some(value.to_string()),
None => match self.shelf.get(key) {
None => None,
Some(value) => {
&self.shelf.set(key, &value);
Some(value)
}
}
}
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn basic() { }
}