Browse Source

Testing const fn

master
Julio Biason 4 years ago
parent
commit
cc905b5d5a
  1. 20
      const.rs

20
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::<i32>().unwrap()));
}
Loading…
Cancel
Save