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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use std::collections::BTreeMap;
use toml::Value;
use error::RefError as RE;
use error::RefErrorKind as REK;
use error::Result;
pub struct RefFlags {
content_hashing: bool,
permission_tracking: bool,
}
impl RefFlags {
pub fn read(v: &Value) -> Result<RefFlags> {
fn get_field(v: &Value, key: &str) -> Result<bool> {
use toml_query::read::TomlValueReadTypeExt;
v.read_bool(key)?.ok_or(RE::from_kind(REK::HeaderFieldMissingError))
}
Ok(RefFlags {
content_hashing: get_field(v, "ref.flags.content_hashing")?,
permission_tracking: get_field(v, "ref.flags.permission_tracking")?,
})
}
pub fn is_often_moving(self, b: bool) -> RefFlags {
self.with_content_hashing(b)
}
pub fn with_content_hashing(mut self, b: bool) -> RefFlags {
self.content_hashing = b;
self
}
pub fn with_permission_tracking(mut self, b: bool) -> RefFlags {
self.permission_tracking = b;
self
}
pub fn get_content_hashing(&self) -> bool {
self.content_hashing
}
pub fn get_permission_tracking(&self) -> bool {
self.permission_tracking
}
}
impl Into<Value> for RefFlags {
fn into(self) -> Value {
let mut btm = BTreeMap::new();
btm.insert(String::from("content_hashing"), Value::Boolean(self.content_hashing));
btm.insert(String::from("permission_tracking"), Value::Boolean(self.permission_tracking));
return Value::Table(btm)
}
}
impl Default for RefFlags {
fn default() -> RefFlags {
RefFlags {
content_hashing: false,
permission_tracking: false,
}
}
}