From cc905b5d5ab76a28ffafa195f23f743bdc0f6bed Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Fri, 28 Aug 2020 09:20:56 -0300 Subject: [PATCH] Testing const fn --- const.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 const.rs diff --git a/const.rs b/const.rs new file mode 100644 index 0000000..9133207 --- /dev/null +++ b/const.rs @@ -0,0 +1,20 @@ +use std::io::stdin; + +const fn double(x: i32) -> i32 { + x * 2 +} + +const FIVE: i32 = 5; +const TEN: i32 = double(FIVE); + +fn main() { + assert_eq!(5, FIVE); + assert_eq!(10, double(FIVE)); + + println!("Your const is {}", double(10)); + + let mut s = String::new(); + stdin().read_line(&mut s).unwrap(); + + println!("Your double: {}", double(s.trim().parse::().unwrap())); +}