Skip to content

Commit 329f3b1

Browse files
committed
[gpx] Remove from_path and tidy up doc comments
1 parent cda4032 commit 329f3b1

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed

coursepointer/src/gpx.rs

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
//! GPX track and waypoint reader
1+
//! GPX track/route and waypoint reader
22
//!
33
//! # Usage
44
//!
5-
//! Provides an iterator that reads in sequence the trackpoints, waypoints,
6-
//! and other relevant items from a GPX track file.
5+
//! Provides an iterator that reads in sequence the trackpoints/routepoints,
6+
//! waypoints, and other relevant items from a GPX track file.
77
//!
8-
//! To use this module, instantiate a [`GpxReader`] by invoking
9-
//! [`GpxReader::from_str`] or [`GpxReader::from_path`]. Iterating over the
10-
//! [`GpxReader`] will produce a sequence of [`GpxItem`] describing the contents
11-
//! of the input.
8+
//! This module treats GPX routes and tracks synonymously, except that tracks
9+
//! may also contain segments.
1210
//!
13-
use std::fs::File;
14-
use std::io::{BufRead, BufReader};
11+
//! To use module, instantiate a [`GpxReader`] by calling
12+
//! [`GpxReader::from_text`] or [`GpxReader::from_reader`]. Iterating over the
13+
//! [`GpxReader`] will produce a sequence of [`GpxItem`] describing the
14+
//! contents of the input.
15+
16+
use std::io::BufRead;
1517
use std::num::ParseFloatError;
16-
use std::path::Path;
1718
use std::{mem, str};
1819

1920
use coretypes::measure::{Degrees, Meters};
2021
use coretypes::{GeoPoint, TypeError};
2122
use quick_xml;
22-
use quick_xml::events::Event;
2323
use quick_xml::events::attributes::AttrError;
24+
use quick_xml::events::Event;
2425
use quick_xml::name::QName;
2526
use quick_xml::reader::Reader;
2627
use thiserror::Error;
@@ -51,18 +52,19 @@ type Result<T> = std::result::Result<T, GpxError>;
5152
pub enum GpxItem {
5253
/// Indicates the start of a GPX track or route. Subsequent
5354
/// `TrackOrRouteName`, `TrackSegment`, and `TrackOrRoutePoint` items belong
54-
/// to this track.
55+
/// to this track or route.
5556
TrackOrRoute,
5657
/// Optionally provides the name of a GPX track or route.
5758
TrackOrRouteName(String),
5859
/// Indicates the start of a GPX track segment. Subsequent
59-
/// `TrackOrRoutePoint` items belong to this segment.
60+
/// `TrackOrRoutePoint` items belong to this segment, until the next
61+
/// `TrackOrRoute` or `TrackSegment` is encountered.
6062
TrackSegment,
6163
/// A point along a track segment or a route, returned in order of its
62-
/// position along the track.
64+
/// position along the track or route.
6365
TrackOrRoutePoint(GeoPoint),
6466
/// A waypoint. Global to the GPX document; not specifically associated
65-
/// with any track.
67+
/// with any track or route.
6668
Waypoint(Waypoint),
6769
}
6870

@@ -157,7 +159,7 @@ where
157159
}
158160

159161
impl GpxReader<&[u8]> {
160-
pub fn from_literal(s: &str) -> GpxReader<&[u8]> {
162+
pub fn from_text(s: &str) -> GpxReader<&[u8]> {
161163
GpxReader::new(Reader::from_reader(s.as_bytes()))
162164
}
163165
}
@@ -168,14 +170,6 @@ impl<R: BufRead> GpxReader<R> {
168170
}
169171
}
170172

171-
impl GpxReader<BufReader<File>> {
172-
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<GpxReader<BufReader<File>>> {
173-
let file = File::open(path)?;
174-
let buf_reader = BufReader::new(file);
175-
Ok(GpxReader::new(Reader::from_reader(buf_reader)))
176-
}
177-
}
178-
179173
#[derive(Default)]
180174
struct NextPtFields {
181175
name: Option<String>,
@@ -358,7 +352,7 @@ where
358352
#[cfg(test)]
359353
mod tests {
360354
use coretypes::measure::{Degrees, Meters};
361-
use coretypes::{GeoPoint, geo_points};
355+
use coretypes::{geo_points, GeoPoint};
362356

363357
use super::{GpxError, GpxItem, GpxReader, Result, Waypoint};
364358

@@ -412,7 +406,7 @@ mod tests {
412406
(37.39888, -122.13498),
413407
];
414408

415-
let reader = GpxReader::from_literal(xml);
409+
let reader = GpxReader::from_text(xml);
416410
let items = reader.collect::<Result<Vec<_>>>()?;
417411
let result = items
418412
.iter()
@@ -447,7 +441,7 @@ mod tests {
447441
(37.39888, -122.13498),
448442
];
449443

450-
let reader = GpxReader::from_literal(xml);
444+
let reader = GpxReader::from_text(xml);
451445
let items = reader.collect::<Result<Vec<_>>>()?;
452446
let result = items
453447
.iter()
@@ -492,7 +486,7 @@ mod tests {
492486
(37.39888, -122.13498, 31.8),
493487
];
494488

495-
let reader = GpxReader::from_literal(xml);
489+
let reader = GpxReader::from_text(xml);
496490
let items = reader.collect::<Result<Vec<_>>>()?;
497491
let result = items
498492
.iter()
@@ -535,7 +529,7 @@ mod tests {
535529
(37.39888, -122.13498, 31.8),
536530
];
537531

538-
let reader = GpxReader::from_literal(xml);
532+
let reader = GpxReader::from_text(xml);
539533
let items = reader.collect::<Result<Vec<_>>>()?;
540534
let result = items
541535
.iter()
@@ -567,7 +561,7 @@ mod tests {
567561
</gpx>
568562
"#;
569563

570-
let reader = GpxReader::from_literal(xml);
564+
let reader = GpxReader::from_text(xml);
571565
let result = reader.collect::<Result<Vec<_>>>();
572566
assert!(
573567
matches!(result, Err(GpxError::GpxSchema(mesg)) if mesg == "trackpoint missing lon attribute".to_owned())
@@ -594,7 +588,7 @@ mod tests {
594588
</gpx>
595589
"#;
596590

597-
let reader = GpxReader::from_literal(xml);
591+
let reader = GpxReader::from_text(xml);
598592
let items = reader.collect::<Result<Vec<_>>>()?;
599593
let result = items
600594
.iter()
@@ -626,7 +620,7 @@ mod tests {
626620
</gpx>
627621
"#;
628622

629-
let reader = GpxReader::from_literal(xml);
623+
let reader = GpxReader::from_text(xml);
630624
let items = reader.collect::<Result<Vec<_>>>()?;
631625

632626
assert_eq!(
@@ -726,7 +720,7 @@ mod tests {
726720
),
727721
];
728722

729-
let reader = GpxReader::from_literal(xml);
723+
let reader = GpxReader::from_text(xml);
730724
let items = reader.collect::<Result<Vec<_>>>()?;
731725
let result = items
732726
.iter()

0 commit comments

Comments
 (0)