yanp/parsers/
bod.rs

1use super::utils::*;
2use crate::errors::NmeaSentenceError;
3use crate::parse::*;
4
5fn build_bod<'a>(
6    sentence: (Option<f32>, Option<f32>, Option<&'a [u8]>, Option<&'a [u8]>),
7) -> Result<BodData<'a>, NmeaSentenceError<'a>> {
8    Ok(BodData {
9        bearing_true: sentence.0,
10        bearing_magnetic: sentence.1,
11        to_waypoint: sentence.2,
12        from_waypoint: sentence.3,
13    })
14}
15
16named!(pub (crate) parse_bod<BodData>,
17    map_res!(
18        do_parse!(
19            bearing_true: opt!(map_res!(take_until!(","), parse_num::<f32>)) >>
20            tag!(",T,") >>
21            bearing_magnetic: opt!(map_res!(take_until!(","), parse_num::<f32>)) >>
22            tag!(",M,") >>
23            to_waypoint: opt!(take_until!(",")) >>
24            char!(',') >>
25            from_waypoint: opt!(take_until!("*")) >>
26            (bearing_true, bearing_magnetic, to_waypoint, from_waypoint)
27        ),
28        build_bod
29    )
30);