Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a8e9708
More practical examples for `Option::and_then`
cyqsimon Feb 10, 2022
73a5f01
Use 0-based idx for array content
cyqsimon Feb 10, 2022
bd421e2
More practical examples for `Result::and_then`
cyqsimon Feb 10, 2022
942eaa7
Add negative example for `Result::and_then`
cyqsimon Feb 11, 2022
cb3cff3
Stop using a placeholder for empty regions in Chalk
matthewjasper Jan 17, 2022
d4fa173
Fix more chalk lowering issues
matthewjasper Feb 9, 2022
1e6d382
Reverse parameter to placeholder substitution in chalk results
matthewjasper Feb 9, 2022
caa10dc
Renumber universes when canonicalizing for Chalk
matthewjasper Feb 9, 2022
7eaecc6
`Result::and_then`: improve basic example
cyqsimon Feb 12, 2022
adfac00
`Result::and_then`: show type conversion
cyqsimon Feb 12, 2022
160faf1
`Option::and_then` basic example: show failure
cyqsimon Feb 12, 2022
daa3c79
add link to format_args! when being mentioned in doc
Feb 12, 2022
f6f93fd
Add note on Windows path behaviour
cyqsimon Feb 12, 2022
1b0dcdc
More informative error message for E0015
fee1-dead Nov 3, 2021
f7f0f84
Improve error messages even more
fee1-dead Dec 9, 2021
b5235ea
bless you
fee1-dead Dec 9, 2021
6d6314f
Rebased and improved errors
fee1-dead Dec 29, 2021
d3acb9d
Handle Fn family trait call errror
fee1-dead Dec 29, 2021
cccf4b2
Adapt new change
fee1-dead Jan 28, 2022
12397ab
Report the selection error when possible
fee1-dead Jan 28, 2022
88d433e
Rebless
fee1-dead Feb 10, 2022
bb45f5d
Remove the RustcDefaultCalls struct
bjorn3 Jun 25, 2021
5730173
Move setup_callbacks call to create_compiler_and_run
bjorn3 Jun 25, 2021
f45ba82
Remove SPAN_DEBUG global
bjorn3 Jan 14, 2022
410145e
Suggest disabling download-ci-llvm option if url fails to download
Badel2 Feb 11, 2022
f718b51
Update chalk tests
matthewjasper Feb 9, 2022
030c508
Address review comment
matthewjasper Feb 11, 2022
a0d603f
Don't relabel to a team if there is already a team label
jackh726 Feb 12, 2022
9efe61d
Fix signature of u8::escape_ascii
clarfonthey Feb 12, 2022
de6e973
Stabilise inherent_ascii_escape (FCP in #77174)
clarfonthey Feb 11, 2022
9d8ef11
make Instant::{duration_since, elapsed, sub} saturating and remove wo…
the8472 Oct 15, 2021
bda2693
Add caveat about the monotonicity guarantee by linking to the later s…
the8472 Jan 7, 2022
376d955
Add panic docs describing old, current and possible future behavior
the8472 Jan 7, 2022
37a1fc5
Capitalize "Rust"
joshtriplett Feb 9, 2022
92613a2
Rollup merge of #89926 - the8472:saturate-instant, r=Mark-Simulacrum
matthiaskrgr Feb 13, 2022
953c4dc
Rollup merge of #90532 - fee1-dead:improve-const-fn-err-msg, r=oli-obk
matthiaskrgr Feb 13, 2022
aff74a1
Rollup merge of #93810 - matthewjasper:chalk-and-canonical-universes,…
matthiaskrgr Feb 13, 2022
783b56b
Rollup merge of #93851 - cyqsimon:option-examples, r=scottmcm
matthiaskrgr Feb 13, 2022
b90a369
Rollup merge of #93885 - Badel2:error-download-ci-llvm, r=Mark-Simula…
matthiaskrgr Feb 13, 2022
5699f68
Rollup merge of #93886 - clarfonthey:stable_ascii_escape, r=Mark-Simu…
matthiaskrgr Feb 13, 2022
2b7f3ee
Rollup merge of #93930 - name1e5s:chore/docs, r=Mark-Simulacrum
matthiaskrgr Feb 13, 2022
dff7d51
Rollup merge of #93936 - bjorn3:simplifications2, r=cjgillot
matthiaskrgr Feb 13, 2022
20ea5c5
Rollup merge of #93944 - jackh726:team-exclude, r=Mark-Simulacrum
matthiaskrgr Feb 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
More practical examples for Option::and_then
  • Loading branch information
cyqsimon committed Feb 10, 2022
commit a8e9708aeb7907979d103f0b56eebba7706c7d0e
21 changes: 15 additions & 6 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,13 +1207,22 @@ impl<T> Option<T> {
/// # Examples
///
/// ```
/// fn sq(x: u32) -> Option<u32> { Some(x * x) }
/// fn nope(_: u32) -> Option<u32> { None }
/// fn squared_string(x: u32) -> Option<String> { Some((x * x).to_string()) }
///
/// assert_eq!(Some(2).and_then(sq).and_then(sq), Some(16));
/// assert_eq!(Some(2).and_then(sq).and_then(nope), None);
/// assert_eq!(Some(2).and_then(nope).and_then(sq), None);
/// assert_eq!(None.and_then(sq).and_then(sq), None);
/// assert_eq!(Some(2).and_then(squared_string), Some(4.to_string()));
/// assert_eq!(None.and_then(squared_string), None);
/// ```
///
/// Often used to chain fallible operations that may return [`None`].
///
/// ```
/// let arr_2d = [["A1", "A2"], ["B1", "B2"]];
///
/// let item_0_1 = arr_2d.get(0).and_then(|row| row.get(1));
/// assert_eq!(item_0_1, Some(&"A2"));
///
/// let item_2_0 = arr_2d.get(2).and_then(|row| row.get(0));
/// assert_eq!(item_2_0, None);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down