File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -1207,10 +1207,13 @@ impl<T> Option<T> {
12071207 /// # Examples
12081208 ///
12091209 /// ```
1210- /// fn squared_string(x: u32) -> Option<String> { Some((x * x).to_string()) }
1210+ /// fn sq_then_to_string(x: u32) -> Option<String> {
1211+ /// x.checked_mul(x).map(|sq| sq.to_string())
1212+ /// }
12111213 ///
1212- /// assert_eq!(Some(2).and_then(squared_string), Some(4.to_string()));
1213- /// assert_eq!(None.and_then(squared_string), None);
1214+ /// assert_eq!(Some(2).and_then(sq_then_to_string), Some(4.to_string()));
1215+ /// assert_eq!(Some(1_000_000).and_then(sq_then_to_string), None); // overflowed!
1216+ /// assert_eq!(None.and_then(sq_then_to_string), None);
12141217 /// ```
12151218 ///
12161219 /// Often used to chain fallible operations that may return [`None`].
You can’t perform that action at this time.
0 commit comments