rustlings/exercises/option/option1.rs

25 lines
567 B
Rust
Raw Permalink Normal View History

2021-07-08 02:58:36 +07:00
// option1.rs
// Make me compile! Execute `rustlings hint option1` for hints
// I AM NOT DONE
// you can modify anything EXCEPT for this function's sig
fn print_number(maybe_number: Option<u16>) {
println!("printing: {}", maybe_number.unwrap());
}
fn main() {
2021-07-08 03:03:42 +07:00
// rustc suggested solutions
print_number(Some(13));
print_number(Some(99));
2021-07-08 02:58:36 +07:00
2021-07-08 03:03:42 +07:00
let numbers: [Option<u16>; 5];
2021-07-08 02:58:36 +07:00
for iter in 0..5 {
let number_to_add: u16 = {
((iter * 1235) + 2) / (4 * 16)
};
2021-07-08 03:03:42 +07:00
numbers[iter as usize] = Some(number_to_add);
2021-07-08 02:58:36 +07:00
}
}