1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2025-01-26 04:22:03 +02:00
lionel-rowe 836134202e
feat(options2): better tests for layered_option
The existing test can be solved with the following:

```rs
        while let Some(integer) = optional_integers.pop() {
            assert_eq!(integer.unwrap(), range);
```

Similarly with `expect(...)`, `unwrap_or(0)`, `unwrap_or_default()`, etc. However, none of these solutions use the learning point of stacking `Option<T>`s.

The updated test can _only_ be solved by stacking `Option<T>`s:

```rs
        while let Some(Some(integer)) = optional_integers.pop() {
            assert_eq!(integer, cursor);
```

With the updated test, using `unwrap` or `expect` will panic when it hits the `None` value, and using `unwrap_or` or `unwrap_or_default` will cause the final `assert_eq!(cursor, 0)`  to panic.
2023-04-21 06:05:25 +01:00
..
2022-07-15 13:24:11 +02:00
2022-07-14 18:11:18 +02:00
2022-10-04 11:43:23 +02:00
2023-04-05 13:24:14 +02:00
2022-09-06 12:10:53 +02:00
2023-01-03 09:22:52 -05:00
2022-07-14 18:11:18 +02:00

Exercise to Book Chapter mapping

Exercise Book Chapter
variables §3.1
functions §3.3
if §3.5
primitive_types §3.2, §4.3
vecs §8.1
move_semantics §4.1-2
structs §5.1, §5.3
enums §6, §18.3
strings §8.2
modules §7
hashmaps §8.3
options §10.1
error_handling §9
generics §10
traits §10.2
tests §11.1
lifetimes §10.3
iterators §13.2-4
threads §16.1-3
smart_pointers §15, §16.3
macros §19.6
clippy §21.4
conversions n/a