Skip to content

Commit

Permalink
move reader::read into gpx::read
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanashworth committed Dec 20, 2017
1 parent 39b1801 commit 5313319
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ extern crate gpx;
use std::io::BufReader;
use std::fs::File;

use gpx::reader;
use gpx::read;
use gpx::{Gpx, Track, Waypoint};

fn main() {
// This XML file actually exists — try it for yourself!
let file = File::open("tests/fixtures/wikipedia_example.gpx").unwrap();
let reader = BufReader::new(file);

// reader::read takes any io::Read and gives a Result<Gpx, Error>.
let gpx: Gpx = reader::read(reader).unwrap();
// read takes any io::Read and gives a Result<Gpx, Error>.
let gpx: Gpx = read(reader).unwrap();

// Each GPX file has multiple "tracks", this takes the first one.
let track: &Track = &gpx.tracks[0];
Expand Down
14 changes: 8 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
//! use std::io::BufReader;
//! use std::fs::File;
//!
//! use gpx::reader;
//! use gpx::read;
//! use gpx::{Gpx, Track, TrackSegment};
//!
//! // This XML file actually exists — try it for yourself!
//! let file = File::open("tests/fixtures/wikipedia_example.gpx").unwrap();
//! let reader = BufReader::new(file);
//!
//! // reader::read takes any io::Read and gives a Result<Gpx, Error>.
//! let gpx: Gpx = reader::read(reader).unwrap();
//! // read takes any io::Read and gives a Result<Gpx, Error>.
//! let gpx: Gpx = read(reader).unwrap();
//!
//! // Each GPX file has multiple "tracks", this takes the first one.
//! let track: &Track = &gpx.tracks[0];
Expand All @@ -42,11 +42,13 @@ extern crate xml;
extern crate chrono;
extern crate geo;

// Export our type structs in the root, along with the read function.
pub use types::*;
pub use reader::read;

mod types;
mod parser;
mod reader;

pub mod reader;
// Errors should be namespaced away.
pub mod errors;

pub mod parser;
4 changes: 2 additions & 2 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ use Gpx;
///
/// ```
/// use std::io::BufReader;
/// use gpx::read;
/// use gpx::Gpx;
/// use gpx::reader;
/// use gpx::errors::*;
///
/// // You can give it anything that implements `std::io::Read`.
/// let data = BufReader::new("<gpx></gpx>".as_bytes());
///
/// let res: Result<Gpx> = reader::read(data);
/// let res: Result<Gpx> = read(data);
///
/// match res {
/// Ok(gpx) => {
Expand Down
8 changes: 4 additions & 4 deletions tests/gpx_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ mod tests {
use geo::{Geometry, ToGeo, Point};
use geo::algorithm::haversine_distance::HaversineDistance;

use gpx::reader;
use gpx::read;

#[test]
fn gpx_reader_read_test_badxml() {
// Should fail with badly formatted XML.
let file = File::open("tests/fixtures/badcharacter.xml").unwrap();
let reader = BufReader::new(file);

let result = reader::read(reader);
let result = read(reader);

assert!(result.is_err());
}
Expand All @@ -37,7 +37,7 @@ mod tests {
let file = File::open("tests/fixtures/wikipedia_example.gpx").unwrap();
let reader = BufReader::new(file);

let result = reader::read(reader);
let result = read(reader);
assert!(result.is_ok());

let result = result.unwrap();
Expand Down Expand Up @@ -70,7 +70,7 @@ mod tests {
let file = File::open("tests/fixtures/garmin-activity.gpx").unwrap();
let reader = BufReader::new(file);

let result = reader::read(reader);
let result = read(reader);
assert!(result.is_ok());
let res = result.unwrap();

Expand Down

0 comments on commit 5313319

Please sign in to comment.