mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-03 09:19:18 +00:00
Refactor options2.rs: Use if let and while let statements
This commit is contained in:
parent
439778465d
commit
9e0f7510d9
@ -3,8 +3,6 @@
|
||||
// Execute `rustlings hint options2` or use the `hint` watch subcommand for a
|
||||
// hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
@ -13,9 +11,9 @@ mod tests {
|
||||
let optional_target = Some(target);
|
||||
|
||||
// TODO: Make this an if let statement whose value is "Some" type
|
||||
word = optional_target {
|
||||
let word = if let Some(target) = optional_target {
|
||||
assert_eq!(word, target);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -32,10 +30,10 @@ mod tests {
|
||||
// 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.
|
||||
integer = optional_integers.pop() {
|
||||
integer = if let Some(cursor) = optional_integers.pop() {
|
||||
assert_eq!(integer, cursor);
|
||||
cursor -= 1;
|
||||
}
|
||||
cursor -= 1
|
||||
};
|
||||
|
||||
assert_eq!(cursor, 0);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user