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
|
use crate::{Error, Result};
use std::collections::BTreeMap;
use iso8601::DateTime;
pub(crate) fn get_str(map: &BTreeMap<String, xmlrpc::Value>, key: &'static str) -> Result<String> {
let value = map
.get(key)
.ok_or(Error::Inexistent(key))?
.as_str()
.ok_or_else(|| Error::Type(key, "String", map.get(key).unwrap().clone()))?;
Ok(value.to_owned())
}
pub(crate) fn get_i32(map: &BTreeMap<String, xmlrpc::Value>, key: &'static str) -> Result<i32> {
let value = map
.get(key)
.ok_or(Error::Inexistent(key))?
.as_i32()
.ok_or_else(|| Error::Type(key, "Int", map.get(key).unwrap().clone()))?;
Ok(value)
}
pub(crate) fn get_bool(map: &BTreeMap<String, xmlrpc::Value>, key: &'static str) -> Result<bool> {
let value = map
.get(key)
.ok_or(Error::Inexistent(key))?
.as_bool()
.ok_or_else(|| Error::Type(key, "Bool", map.get(key).unwrap().clone()))?;
Ok(value)
}
pub(crate) fn get_datetime(
map: &BTreeMap<String, xmlrpc::Value>,
key: &'static str,
) -> Result<DateTime> {
let value = map
.get(key)
.ok_or(Error::Inexistent(key))?
.as_datetime()
.ok_or_else(|| Error::Type(key, "DateTime", map.get(key).unwrap().clone()))?;
Ok(value)
}
pub(crate) fn get_array(
map: &BTreeMap<String, xmlrpc::Value>,
key: &'static str,
) -> Result<Vec<xmlrpc::Value>> {
let value = map
.get(key)
.ok_or(Error::Inexistent(key))?
.as_array()
.ok_or_else(|| Error::Type(key, "Array", map.get(key).unwrap().clone()))?;
Ok(value.to_vec())
}
pub(crate) fn get_map(
map: &BTreeMap<String, xmlrpc::Value>,
key: &'static str,
) -> Result<BTreeMap<String, xmlrpc::Value>> {
let value = map
.get(key)
.ok_or(Error::Inexistent(key))?
.as_struct()
.ok_or_else(|| Error::Type(key, "Struct", map.get(key).unwrap().clone()))?;
Ok(value.to_owned())
}
pub mod nameserver;
|