We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
?
1 parent 3aa53e0 commit 28eba7bCopy full SHA for 28eba7b
src/language/nullability-and-optionality.md
@@ -85,6 +85,16 @@ let person1: Option<Person> = None;
85
println!("{:?}", person1.and_then(|p| p.name.map(|name| name.first_name))); // None
86
```
87
88
+The `?` operator (mentioned in the previous chapter), can also be used to handle `Option`s.
89
+It returns from the function with `None` if a `None` is encountered, or else continues with the
90
+`Some` value:
91
+```rust
92
+fn foo(optional: Option<i32>) -> Option<String> {
93
+ let value = optional?;
94
+ Some(value.to_string())
95
+}
96
+```
97
+
98
## Null-coalescing operator
99
100
The null-coalescing operator (`??`) is typically used to default to another
0 commit comments