1pub mod mgf_parser;
6pub mod mzml_parser;
7
8use std::str::FromStr;
9
10#[derive(Debug, PartialEq)]
24pub enum Format {
25 Json,
27
28 Mgf,
30
31 MzML,
33}
34
35impl FromStr for Format {
37 type Err = &'static str;
38
39 fn from_str(s: &str) -> Result<Self, Self::Err> {
40 match s {
41 "json" => Ok(Self::Json),
42 "mgf" => Ok(Self::Mgf),
43 "mzml" => Ok(Self::MzML),
44 _ => Err("Cannot parse input format."),
45 }
46 }
47}
48
49mod tests {
50 use crate::io::Format;
51 use std::str::FromStr;
52
53 #[test]
54 fn from_str() {
55 let inputs = vec!["json", "mgf", "mzml"];
56 let expected = vec![Format::Json, Format::Mgf, Format::MzML];
57
58 let actual: Vec<Format> = inputs
59 .into_iter()
60 .map(|i| Format::from_str(i).unwrap())
61 .collect();
62 assert_eq!(expected, actual);
63 }
64}