forked from rust-lang/rustlings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options2.rs
42 lines (35 loc) · 1.08 KB
/
options2.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// options2.rs
//
// Execute `rustlings hint options2` or use the `hint` watch subcommand for a
// hint.
#[cfg(test)]
mod tests {
#[test]
fn simple_option() {
let target = "rustlings";
let optional_target = Some(target);
// TODO: Make this an if let statement whose value is "Some" type
if let word = optional_target {
assert_eq!(word, Some(target));
}
}
#[test]
fn layered_option() {
let range = 10;
let mut optional_integers: Vec<Option<i8>> = vec![None];
for i in 1..(range + 1) {
optional_integers.push(Some(i));
}
let mut cursor = range;
// TODO: make this a while let statement - remember that vector.pop also
// adds another layer of Option<T>. You can stack `Option<T>`s into
// while let and if let.
while let Some(integer) = optional_integers.pop() {
if let Some(i) = integer {
assert_eq!(integer, Some(cursor));
cursor -= 1;
}
}
assert_eq!(cursor, 0);
}
}