Created
October 19, 2017 16:33
-
-
Save mre/e38a961188c14206caf2028b13526f37 to your computer and use it in GitHub Desktop.
Convert String to Option<f64>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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