Skip to content

Commit

Permalink
Revert "infra: reformat code with rustfmt 0.8.2"
Browse files Browse the repository at this point in the history
This reverts commit 7573943.
  • Loading branch information
Dushistov committed Sep 13, 2018
1 parent 7573943 commit cdbe395
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 76 deletions.
4 changes: 2 additions & 2 deletions examples/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
94 changes: 30 additions & 64 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -69,12 +69,8 @@ named!(
do_parse_nmea_sentence<NmeaSentence>,
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
Expand Down Expand Up @@ -132,12 +128,9 @@ named!(
parse_gsv_sat_info<Satellite>,
map_res!(
do_parse!(
prn: map_res!(digit, parse_num::<u32>)
>> char!(',')
>> elevation: opt!(map_res!(digit, parse_num::<i32>))
>> char!(',')
>> azimuth: opt!(map_res!(digit, parse_num::<i32>))
>> char!(',')
prn: map_res!(digit, parse_num::<u32>) >> char!(',')
>> elevation: opt!(map_res!(digit, parse_num::<i32>)) >> char!(',')
>> azimuth: opt!(map_res!(digit, parse_num::<i32>)) >> char!(',')
>> signal_noise: opt!(map_res!(complete!(digit), parse_num::<i32>))
>> dbg!(alt!(eof!() | tag!(",")))
>> (prn, elevation, azimuth, signal_noise)
Expand Down Expand Up @@ -170,12 +163,9 @@ named!(
do_parse_gsv<GsvData>,
map_res!(
do_parse!(
number_of_sentences: map_res!(digit, parse_num::<u16>)
>> char!(',')
>> sentence_index: map_res!(digit, parse_num::<u16>)
>> char!(',')
>> total_number_of_sats: map_res!(digit, parse_num::<u16>)
>> char!(',')
number_of_sentences: map_res!(digit, parse_num::<u16>) >> char!(',')
>> sentence_index: map_res!(digit, parse_num::<u16>) >> char!(',')
>> total_number_of_sats: map_res!(digit, parse_num::<u16>) >> char!(',')
>> sat0: opt!(complete!(parse_gsv_sat_info))
>> sat1: opt!(complete!(parse_gsv_sat_info))
>> sat2: opt!(complete!(parse_gsv_sat_info))
Expand All @@ -187,7 +177,7 @@ named!(
sat0,
sat1,
sat2,
sat3,
sat3
)
),
construct_gsv_data
Expand Down Expand Up @@ -329,8 +319,7 @@ named!(
parse_hms<NaiveTime>,
map_res!(
do_parse!(
hour: map_res!(take!(2), parse_num::<u32>)
>> min: map_res!(take!(2), parse_num::<u32>)
hour: map_res!(take!(2), parse_num::<u32>) >> min: map_res!(take!(2), parse_num::<u32>)
>> sec: map_res!(take_until!(","), parse_float_num::<f64>)
>> (hour, min, sec)
),
Expand Down Expand Up @@ -374,13 +363,10 @@ named!(
map_res!(
do_parse!(
lat_deg: map_res!(take!(2), parse_num::<u8>)
>> lat_min: map_res!(float_number, parse_float_num::<f64>)
>> char!(',')
>> lat_dir: one_of!("NS")
>> char!(',')
>> lat_min: map_res!(float_number, parse_float_num::<f64>) >> char!(',')
>> lat_dir: one_of!("NS") >> char!(',')
>> lon_deg: map_res!(take!(3), parse_num::<u8>)
>> lon_min: map_res!(float_number, parse_float_num::<f64>)
>> char!(',')
>> lon_min: map_res!(float_number, parse_float_num::<f64>) >> char!(',')
>> lon_dir: one_of!("EW")
>> (lat_deg, lat_min, lat_dir, lon_deg, lon_min, lon_dir)
),
Expand Down Expand Up @@ -423,12 +409,8 @@ named!(
do_parse_gga<GgaData>,
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::<u32>)))
>> char!(',')
>> hdop: opt!(complete!(map_res!(float_number, parse_float_num::<f32>)))
Expand All @@ -450,7 +432,7 @@ named!(
tracked_sats,
hdop,
altitude,
geoid_height,
geoid_height
)
),
|data: (
Expand All @@ -460,7 +442,7 @@ named!(
Option<u32>,
Option<f32>,
Option<f32>,
Option<f32>,
Option<f32>
)|
-> std::result::Result<GgaData, &'static str> {
Ok(GgaData {
Expand Down Expand Up @@ -575,10 +557,8 @@ named!(
parse_date<NaiveDate>,
map_res!(
do_parse!(
day: map_res!(take!(2), parse_num::<u8>)
>> month: map_res!(take!(2), parse_num::<u8>)
>> year: map_res!(take!(2), parse_num::<u8>)
>> (day, month, year)
day: map_res!(take!(2), parse_num::<u8>) >> month: map_res!(take!(2), parse_num::<u8>)
>> year: map_res!(take!(2), parse_num::<u8>) >> (day, month, year)
),
|data: (u8, u8, u8)| -> Result<NaiveDate, &'static str> {
let (day, month, year) = (u32::from(data.0), u32::from(data.1), i32::from(data.2));
Expand All @@ -597,12 +577,8 @@ named!(
do_parse_rmc<RmcData>,
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::<f32>)))
>> char!(',')
Expand All @@ -614,7 +590,7 @@ named!(
lat_lon,
speed_over_ground,
true_course,
date,
date
)
),
|data: (
Expand All @@ -623,7 +599,7 @@ named!(
Option<(f64, f64)>,
Option<f32>,
Option<f32>,
Option<NaiveDate>,
Option<NaiveDate>
)|
-> Result<RmcData, &'static str> {
Ok(RmcData {
Expand Down Expand Up @@ -763,12 +739,9 @@ type GsaTail = (Vec<Option<u32>>, Option<f32>, Option<f32>, Option<f32>);
named!(
do_parse_gsa_tail<GsaTail>,
do_parse!(
prns: gsa_prn_fields_parse
>> pdop: map_res!(float_number, parse_float_num::<f32>)
>> char!(',')
>> hdop: map_res!(float_number, parse_float_num::<f32>)
>> char!(',')
>> vdop: map_res!(float_number, parse_float_num::<f32>)
prns: gsa_prn_fields_parse >> pdop: map_res!(float_number, parse_float_num::<f32>)
>> char!(',') >> hdop: map_res!(float_number, parse_float_num::<f32>)
>> char!(',') >> vdop: map_res!(float_number, parse_float_num::<f32>)
>> (prns, Some(pdop), Some(hdop), Some(vdop))
)
);
Expand All @@ -789,10 +762,7 @@ named!(
do_parse_gsa<GsaData>,
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)
),
Expand Down Expand Up @@ -978,13 +948,9 @@ named!(
map_res!(
do_parse!(
true_course: opt!(map_res!(complete!(float_number), parse_float_num::<f32>))
>> char!(',')
>> opt!(complete!(char!('T')))
>> char!(',')
>> char!(',') >> opt!(complete!(char!('T'))) >> char!(',')
>> magn_course: opt!(map_res!(complete!(float_number), parse_float_num::<f32>))
>> char!(',')
>> opt!(complete!(char!('M')))
>> char!(',')
>> char!(',') >> opt!(complete!(char!('M'))) >> char!(',')
>> knots_ground_speed:
opt!(map_res!(complete!(float_number), parse_float_num::<f32>))
>> char!(',') >> opt!(complete!(char!('N')))
Expand Down
10 changes: 4 additions & 6 deletions tests/file_log_parser.rs
Original file line number Diff line number Diff line change
@@ -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: Error>(e: E) -> String {
e.description().to_string()
Expand All @@ -14,11 +14,9 @@ fn process_file(n: &Path) -> Result<Vec<String>, 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));
}
Expand Down

0 comments on commit cdbe395

Please sign in to comment.