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
use std::num::ParseIntError;
use super::raws::tags;
impl super::DFParser {
/// It takes a slice of strings, parses the first two strings as unsigned 16-bit integers, and returns a
/// two-element array of unsigned 16-bit integers
///
/// Arguments:
///
/// * `split`: &[&str] - This is the array of strings that we're going to parse.
///
/// Returns:
///
/// A Result<[u16; 2], `ParseIntError`>
pub fn parse_min_max_range(split: &[&str]) -> Result<[u16; 2], ParseIntError> {
let min: u16 = match split[0].parse() {
Ok(n) => n,
Err(e) => {
log::error!("min_value parsing error\n{:?}", e);
return Err(e);
}
};
let max: u16 = match split[1].parse() {
Ok(n) => n,
Err(e) => {
log::error!("max_value parsing error\n{:?}", e);
return Err(e);
}
};
Ok([min, max])
}
/// It takes a slice of strings, parses them into integers, and returns a `DFBodySize` struct
///
/// Arguments:
///
/// * `split`: &[&str]
///
/// Returns:
///
/// A `Result<tags::DFBodySize, ParseIntError>`
pub fn parse_body_size(split: &[&str]) -> Result<tags::DFBodySize, ParseIntError> {
let years: u32 = match split[0].parse() {
Ok(n) => n,
Err(e) => {
log::error!("Unable to parse years from BODY_SIZE\n{:?}", e);
return Err(e);
}
};
let days: u32 = match split[1].parse() {
Ok(n) => n,
Err(e) => {
log::error!("Unable to parse days from BODY_SIZE\n{:?}", e);
return Err(e);
}
};
let size: u32 = match split[2].parse() {
Ok(n) => n,
Err(e) => {
log::error!("Unable to parse size from BODY_SIZE\n{:?}", e);
return Err(e);
}
};
Ok(tags::DFBodySize::new(years, days, size))
}
}