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
pub mod mgf_parser;
pub mod mzml_parser;
use std::str::FromStr;
#[derive(Debug, PartialEq)]
pub enum Format {
Json,
Mgf,
MzML,
}
impl FromStr for Format {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"json" => Ok(Self::Json),
"mgf" => Ok(Self::Mgf),
"mzml" => Ok(Self::MzML),
_ => Err("Cannot parse input format."),
}
}
}
mod tests {
use crate::io::Format;
use std::str::FromStr;
#[test]
fn from_str() {
let inputs = vec!["json", "mgf", "mzml"];
let expected = vec![Format::Json, Format::Mgf, Format::MzML];
let actual: Vec<Format> = inputs
.into_iter()
.map(|i| Format::from_str(i).unwrap())
.collect();
assert_eq!(expected, actual);
}
}