parse

Function parse 

Source
pub fn parse(raw: &str) -> Result<Spot, ParseError>
Expand description

Parse a spot received from a DX Cluster into a struct.

§Arguments

  • raw: A raw spot that is already cleaned from newline or bell characters etc.

§Result

In case the spot was parsed successfully, the structure containing the spot shall be returned. In case of an error the occurred error shall be returned.

Examples found in repository?
examples/basic.rs (line 16)
7fn main() {
8    let args: Vec<String> = env::args().collect();
9    let retval;
10
11    if args.len() != 2 {
12        eprintln!("Invalid number of arguments.");
13        eprintln!("Usage: {} <spot>", args[0]);
14        retval = 1;
15    } else {
16        match dxclparser::parse(args[1].trim().trim_end_matches('\u{0007}')) {
17            Ok(spot) => {
18                println!("{}", spot.to_json());
19                retval = 0;
20            }
21            Err(e) => {
22                eprintln!("Failed to parse spot ({})", e);
23                retval = 1;
24            }
25        }
26    }
27
28    process::exit(retval);
29}
More examples
Hide additional examples
examples/file.rs (line 20)
8fn main() {
9    let args: Vec<String> = env::args().collect();
10
11    if args.len() != 2 {
12        eprintln!("Invalid number of arguments.");
13        eprintln!("Usage: {} <file>", args[0]);
14    } else {
15        let filepath = Path::new(&args[1]);
16        let file = File::open(filepath).expect("Failed to open file");
17        let reader = io::BufReader::new(file).lines();
18
19        for line in reader {
20            match dxclparser::parse(line.unwrap().trim().trim_end_matches('\u{0007}')) {
21                Ok(spot) => {
22                    println!("{}", spot.to_json());
23                }
24                Err(e) => {
25                    eprintln!("Failed to parse spot ({})", e);
26                }
27            }
28        }
29    }
30}
examples/type.rs (line 16)
7fn main() {
8    let args: Vec<String> = env::args().collect();
9    let retval;
10
11    if args.len() != 2 {
12        eprintln!("Invalid number of arguments.");
13        eprintln!("Usage: {} <spot>", args[0]);
14        retval = 1;
15    } else {
16        match dxclparser::parse(args[1].trim().trim_end_matches('\u{0007}')) {
17            Ok(spot) => {
18                match spot {
19                    dxclparser::Spot::DX(dx) => println!("Found a DX spot from {}", dx.call_de),
20                    dxclparser::Spot::WWV(wwv) => println!("Found a WWV spot from {}", wwv.call_de),
21                    dxclparser::Spot::WCY(wcy) => println!("Found a WCY spot from {}", wcy.call_de),
22                    dxclparser::Spot::WX(wx) => println!("Found a WX spot from {}", wx.call_de),
23                    dxclparser::Spot::ToAll(toall) => {
24                        println!("Found a ToAll spot from {}", toall.call_de)
25                    }
26                    dxclparser::Spot::ToLocal(tolocal) => {
27                        println!("Found a ToLocal spot from {}", tolocal.call_de)
28                    }
29                }
30                retval = 0;
31            }
32            Err(e) => {
33                eprintln!("Failed to parse spot ({})", e);
34                retval = 1;
35            }
36        }
37    }
38
39    process::exit(retval);
40}