diff --git a/examples/serial.rs b/examples/serial.rs index e17c980..14b5fbd 100644 --- a/examples/serial.rs +++ b/examples/serial.rs @@ -15,9 +15,9 @@ extern crate nmea; -use std::env; -use std::fs::File; use std::io::{BufRead, BufReader}; +use std::fs::File; +use std::env; fn main() { let mut nmea = nmea::Nmea::new(); diff --git a/src/lib.rs b/src/lib.rs index d462246..33f51b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -172,8 +172,7 @@ impl<'a> Nmea { fn merge_gsv_data(&mut self, data: GsvData) -> Result<(), &'static str> { { - let d = self - .satellites_scan + let d = self.satellites_scan .get_mut(&data.gnss_type) .ok_or("Invalid GNSS type")?; // Adjust size to this scan @@ -348,8 +347,7 @@ impl<'a> Nmea { match self.fix_type { Some(FixType::Invalid) | None => Ok(FixType::Invalid), Some(ref fix_type) - if self - .required_sentences_for_nav + if self.required_sentences_for_nav .is_subset(&self.sentences_for_this_time) => { Ok(fix_type.clone()) diff --git a/src/parse.rs b/src/parse.rs index b43a05a..17ee3e9 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -5,9 +5,9 @@ use chrono::{NaiveDate, NaiveTime}; use nom; use nom::{digit, AsChar, IError, IResult}; -use FixType; use GnssType; use Satellite; +use FixType; use SentenceType; pub struct NmeaSentence<'a> { @@ -69,12 +69,8 @@ named!( do_parse_nmea_sentence, map_res!( do_parse!( - char!('$') - >> talker_id: take!(2) - >> message_id: take!(3) - >> char!(',') - >> data: take_until!("*") - >> cs: parse_checksum + char!('$') >> talker_id: take!(2) >> message_id: take!(3) >> char!(',') + >> data: take_until!("*") >> cs: parse_checksum >> (talker_id, message_id, data, cs) ), construct_sentence @@ -132,12 +128,9 @@ named!( parse_gsv_sat_info, map_res!( do_parse!( - prn: map_res!(digit, parse_num::) - >> char!(',') - >> elevation: opt!(map_res!(digit, parse_num::)) - >> char!(',') - >> azimuth: opt!(map_res!(digit, parse_num::)) - >> char!(',') + prn: map_res!(digit, parse_num::) >> char!(',') + >> elevation: opt!(map_res!(digit, parse_num::)) >> char!(',') + >> azimuth: opt!(map_res!(digit, parse_num::)) >> char!(',') >> signal_noise: opt!(map_res!(complete!(digit), parse_num::)) >> dbg!(alt!(eof!() | tag!(","))) >> (prn, elevation, azimuth, signal_noise) @@ -170,12 +163,9 @@ named!( do_parse_gsv, map_res!( do_parse!( - number_of_sentences: map_res!(digit, parse_num::) - >> char!(',') - >> sentence_index: map_res!(digit, parse_num::) - >> char!(',') - >> total_number_of_sats: map_res!(digit, parse_num::) - >> char!(',') + number_of_sentences: map_res!(digit, parse_num::) >> char!(',') + >> sentence_index: map_res!(digit, parse_num::) >> char!(',') + >> total_number_of_sats: map_res!(digit, parse_num::) >> char!(',') >> sat0: opt!(complete!(parse_gsv_sat_info)) >> sat1: opt!(complete!(parse_gsv_sat_info)) >> sat2: opt!(complete!(parse_gsv_sat_info)) @@ -187,7 +177,7 @@ named!( sat0, sat1, sat2, - sat3, + sat3 ) ), construct_gsv_data @@ -329,8 +319,7 @@ named!( parse_hms, map_res!( do_parse!( - hour: map_res!(take!(2), parse_num::) - >> min: map_res!(take!(2), parse_num::) + hour: map_res!(take!(2), parse_num::) >> min: map_res!(take!(2), parse_num::) >> sec: map_res!(take_until!(","), parse_float_num::) >> (hour, min, sec) ), @@ -374,13 +363,10 @@ named!( map_res!( do_parse!( lat_deg: map_res!(take!(2), parse_num::) - >> lat_min: map_res!(float_number, parse_float_num::) - >> char!(',') - >> lat_dir: one_of!("NS") - >> char!(',') + >> lat_min: map_res!(float_number, parse_float_num::) >> char!(',') + >> lat_dir: one_of!("NS") >> char!(',') >> lon_deg: map_res!(take!(3), parse_num::) - >> lon_min: map_res!(float_number, parse_float_num::) - >> char!(',') + >> lon_min: map_res!(float_number, parse_float_num::) >> char!(',') >> lon_dir: one_of!("EW") >> (lat_deg, lat_min, lat_dir, lon_deg, lon_min, lon_dir) ), @@ -423,12 +409,8 @@ named!( do_parse_gga, map_res!( do_parse!( - time: opt!(complete!(parse_hms)) - >> char!(',') - >> lat_lon: parse_lat_lon - >> char!(',') - >> fix_quality: dbg!(one_of!("012345678")) - >> char!(',') + time: opt!(complete!(parse_hms)) >> char!(',') >> lat_lon: parse_lat_lon >> char!(',') + >> fix_quality: dbg!(one_of!("012345678")) >> char!(',') >> tracked_sats: opt!(complete!(map_res!(digit, parse_num::))) >> char!(',') >> hdop: opt!(complete!(map_res!(float_number, parse_float_num::))) @@ -450,7 +432,7 @@ named!( tracked_sats, hdop, altitude, - geoid_height, + geoid_height ) ), |data: ( @@ -460,7 +442,7 @@ named!( Option, Option, Option, - Option, + Option )| -> std::result::Result { Ok(GgaData { @@ -575,10 +557,8 @@ named!( parse_date, map_res!( do_parse!( - day: map_res!(take!(2), parse_num::) - >> month: map_res!(take!(2), parse_num::) - >> year: map_res!(take!(2), parse_num::) - >> (day, month, year) + day: map_res!(take!(2), parse_num::) >> month: map_res!(take!(2), parse_num::) + >> year: map_res!(take!(2), parse_num::) >> (day, month, year) ), |data: (u8, u8, u8)| -> Result { let (day, month, year) = (u32::from(data.0), u32::from(data.1), i32::from(data.2)); @@ -597,12 +577,8 @@ named!( do_parse_rmc, map_res!( do_parse!( - time: opt!(complete!(parse_hms)) - >> char!(',') - >> status_of_fix: one_of!("ADV") - >> char!(',') - >> lat_lon: parse_lat_lon - >> char!(',') + time: opt!(complete!(parse_hms)) >> char!(',') >> status_of_fix: one_of!("ADV") + >> char!(',') >> lat_lon: parse_lat_lon >> char!(',') >> speed_over_ground: opt!(complete!(map_res!(float_number, parse_float_num::))) >> char!(',') @@ -614,7 +590,7 @@ named!( lat_lon, speed_over_ground, true_course, - date, + date ) ), |data: ( @@ -623,7 +599,7 @@ named!( Option<(f64, f64)>, Option, Option, - Option, + Option )| -> Result { Ok(RmcData { @@ -763,12 +739,9 @@ type GsaTail = (Vec>, Option, Option, Option); named!( do_parse_gsa_tail, do_parse!( - prns: gsa_prn_fields_parse - >> pdop: map_res!(float_number, parse_float_num::) - >> char!(',') - >> hdop: map_res!(float_number, parse_float_num::) - >> char!(',') - >> vdop: map_res!(float_number, parse_float_num::) + prns: gsa_prn_fields_parse >> pdop: map_res!(float_number, parse_float_num::) + >> char!(',') >> hdop: map_res!(float_number, parse_float_num::) + >> char!(',') >> vdop: map_res!(float_number, parse_float_num::) >> (prns, Some(pdop), Some(hdop), Some(vdop)) ) ); @@ -789,10 +762,7 @@ named!( do_parse_gsa, map_res!( do_parse!( - mode1: one_of!("MA") - >> char!(',') - >> mode2: one_of!("123") - >> char!(',') + mode1: one_of!("MA") >> char!(',') >> mode2: one_of!("123") >> char!(',') >> tail: alt_complete!(do_parse_empty_gsa_tail | do_parse_gsa_tail) >> (mode1, mode2, tail) ), @@ -978,13 +948,9 @@ named!( map_res!( do_parse!( true_course: opt!(map_res!(complete!(float_number), parse_float_num::)) - >> char!(',') - >> opt!(complete!(char!('T'))) - >> char!(',') + >> char!(',') >> opt!(complete!(char!('T'))) >> char!(',') >> magn_course: opt!(map_res!(complete!(float_number), parse_float_num::)) - >> char!(',') - >> opt!(complete!(char!('M'))) - >> char!(',') + >> char!(',') >> opt!(complete!(char!('M'))) >> char!(',') >> knots_ground_speed: opt!(map_res!(complete!(float_number), parse_float_num::)) >> char!(',') >> opt!(complete!(char!('N'))) diff --git a/tests/file_log_parser.rs b/tests/file_log_parser.rs index 0f0e5e6..39fe6c1 100644 --- a/tests/file_log_parser.rs +++ b/tests/file_log_parser.rs @@ -1,9 +1,9 @@ extern crate nmea; +use std::path::Path; use std::error::Error; -use std::fs::File; use std::io::{BufRead, BufReader}; -use std::path::Path; +use std::fs::File; fn err_to_string(e: E) -> String { e.description().to_string() @@ -14,11 +14,9 @@ fn process_file(n: &Path) -> Result, String> { let mut nmea = nmea::Nmea::new(); let mut ret = Vec::with_capacity(15_000); for (num, line) in input.lines().enumerate() { - let line = line - .map_err(err_to_string) + let line = line.map_err(err_to_string) .map_err(|s| format!("{} at line {}", s, num + 1))?; - let parse_res = nmea - .parse(&line) + let parse_res = nmea.parse(&line) .map_err(|s| format!("{} at line {}", s, num + 1))?; ret.push(format!("{:?}", parse_res)); }