Last active
December 23, 2018 22:31
-
-
Save dns2utf8/a1288783cdd387f6d3381f8697d98c45 to your computer and use it in GitHub Desktop.
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
// source: https://gist.github.com/dns2utf8/a1288783cdd387f6d3381f8697d98c45 | |
extern crate rand; // 0.6.1 | |
fn main() { | |
let number: f64 = rand::random(); | |
let int = maybe_round(number); | |
println!("Hello, {} => {:?}!", number, int); | |
} | |
fn maybe_round(number: f64) -> Result<u64, ()> { | |
if number.is_normal() { | |
Ok(number.round() as u64) | |
} else { | |
Err(()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run on play.rust-lang.org