gpx/
reader.rs

1//! Reads an activity from GPX format.
2
3use std::io::Read;
4
5use crate::errors::GpxResult;
6use crate::parser::{create_context, gpx};
7use crate::{Gpx, GpxVersion};
8
9/// Reads an activity in GPX format.
10///
11/// Takes any `std::io::Read` as its reader, and returns a
12/// `Result<Gpx>`.
13///
14/// ```
15/// use std::io::BufReader;
16/// use gpx::read;
17/// use gpx::Gpx;
18/// use gpx::errors::GpxError;
19///
20/// // You can give it anything that implements `std::io::Read`.
21/// let data = BufReader::new("<gpx></gpx>".as_bytes());
22///
23/// let res: Result<Gpx, GpxError> = read(data);
24///
25/// match res {
26///     Ok(gpx) => {
27///         // ..
28///     }
29///
30///     Err(e) => {
31///         // ..
32///     }
33/// }
34/// ```
35pub fn read<R: Read>(reader: R) -> GpxResult<Gpx> {
36    gpx::consume(&mut create_context(reader, GpxVersion::Unknown))
37}