Skip to content

Commit 4bfa227

Browse files
committed
mark some elements as inline code
1 parent 127e7dc commit 4bfa227

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
- [Error handling](error.md)
153153
- [`panic`](error/panic.md)
154154
- [`Option` & `unwrap`](error/option_unwrap.md)
155-
- [Unpacking options with ?](error/option_unwrap/question_mark.md)
155+
- [Unpacking options with `?`](error/option_unwrap/question_mark.md)
156156
- [Combinators: `map`](error/option_unwrap/map.md)
157157
- [Combinators: `and_then`](error/option_unwrap/and_then.md)
158158
- [`Result`](error/result.md)

src/error/option_unwrap/question_mark.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
# Unpacking options with ?
1+
# Unpacking options with `?`
22

3-
You can unpack Options by using `match` statements, but it's often easier to use the `?` operator. If `x` is an `Option`, then evaluating `x?` will return the underlying value if `x` is Some, otherwise it will terminate whatever function is being executed and return `None`.
3+
You can unpack `Option`s by using `match` statements, but it's often easier to
4+
use the `?` operator. If `x` is an `Option`, then evaluating `x?` will return
5+
the underlying value if `x` is `Some`, otherwise it will terminate whatever
6+
function is being executed and return `None`.
47

58
```rust,editable
69
fn next_birthday(current_age: Option<u8>) -> Option<String> {
7-
// If `current_age` is None, this returns None.
8-
// If `current_age` is Some, the inner u8 gets assigned to `next_age`
10+
// If `current_age` is `None`, this returns `None`.
11+
// If `current_age` is `Some`, the inner `u8` gets assigned to `next_age`
912
let next_age: u8 = current_age?;
1013
Some(format!("Next year I will be {}", next_age))
1114
}
1215
```
1316

14-
You can chain many ?s together to make your code much more readable.
17+
You can chain many `?`s together to make your code much more readable.
1518

1619
```rust,editable
1720
struct Person {
@@ -30,10 +33,10 @@ struct PhoneNumber {
3033
}
3134
3235
impl Person {
33-
36+
3437
// Gets the area code of the phone number of the person's job, if it exists.
3538
fn work_phone_area_code(&self) -> Option<u8> {
36-
// This would need many nested `match` statements without the ? operator.
39+
// This would need many nested `match` statements without the `?` operator.
3740
// It would take a lot more code - try writing it yourself and see which
3841
// is easier.
3942
self.job?.phone_number?.area_code
@@ -52,4 +55,4 @@ fn main() {
5255
5356
assert_eq!(p.work_phone_area_code(), Some(61));
5457
}
55-
```
58+
```

0 commit comments

Comments
 (0)