Skip to content

Instantly share code, notes, and snippets.

@mre
Created October 19, 2017 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mre/e38a961188c14206caf2028b13526f37 to your computer and use it in GitHub Desktop.
Save mre/e38a961188c14206caf2028b13526f37 to your computer and use it in GitHub Desktop.
Convert String to Option<f64>
fn main() {
let test: String = "0.123".into();
let out = test.parse::<f64>().ok(); // parse test into Some(0.123) here
// my failed attempt:
// time_index: Some(fields[3].parse::<f64>().unwrap_or_default()),
let out = test.parse::<f64>().ok(); // parse test into Some(0.123) here
assert_eq!(out, Some(0.123));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment