File tree 1 file changed +6
-3
lines changed
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> {
1207
1207
/// # Examples
1208
1208
///
1209
1209
/// ```
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
+ /// }
1211
1213
///
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);
1214
1217
/// ```
1215
1218
///
1216
1219
/// Often used to chain fallible operations that may return [`None`].
You can’t perform that action at this time.
0 commit comments