Skip to content

Instantly share code, notes, and snippets.

@stepankuzmin
Last active May 4, 2019 12:02
Show Gist options
  • Save stepankuzmin/16f3c95f354ce5065d3f59ffd890b8a4 to your computer and use it in GitHub Desktop.
Save stepankuzmin/16f3c95f354ce5065d3f59ffd890b8a4 to your computer and use it in GitHub Desktop.
Parse waypoints with Rust
// https://doc.rust-lang.org/rust-by-example/error/iter_result.html#fail-the-entire-operation-with-collect
use std::num::ParseFloatError;
fn get_waypoints(path: String) -> Result<Vec<Vec<f64>>, ParseFloatError> {
path
.split(';')
.map(|waypoint| waypoint.split(',').map(|c| c.parse::<f64>()).collect())
.collect()
}
fn main() {
let path = String::from("37.60,55.65;37.61,55.62");
let waypoints = get_waypoints(path);
println!("{:?}", waypoints);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment