Auto merge of #116866 - slanterns:inspect-stabilize, r=BurntSushi
Stabilize `result_option_inspect` This PR stabilizes `result_option_inspect`: ```rust // core::option impl Option<T> { pub fn inspect<F: FnOnce(&T)>(self, f: F) -> Self; } // core::result impl Result<T, E> { pub fn inspect<F: FnOnce(&T)>(self, f: F) -> Self; pub fn inspect_err<F: FnOnce(&E)>(self, f: F) -> Self; } ``` <br> Tracking issue: https://github.com/rust-lang/rust/issues/91345. Implementation PR: https://github.com/rust-lang/rust/pull/91346. Closes https://github.com/rust-lang/rust/issues/91345.
This commit is contained in:
commit
85b8450466
5 changed files with 4 additions and 16 deletions
|
@ -10,7 +10,6 @@
|
||||||
#![feature(if_let_guard)]
|
#![feature(if_let_guard)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(result_option_inspect)]
|
|
||||||
#![feature(rustc_attrs)]
|
#![feature(rustc_attrs)]
|
||||||
#![feature(yeet_expr)]
|
#![feature(yeet_expr)]
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
|
|
|
@ -59,7 +59,6 @@
|
||||||
#![feature(extract_if)]
|
#![feature(extract_if)]
|
||||||
#![feature(intra_doc_pointers)]
|
#![feature(intra_doc_pointers)]
|
||||||
#![feature(yeet_expr)]
|
#![feature(yeet_expr)]
|
||||||
#![feature(result_option_inspect)]
|
|
||||||
#![feature(const_option)]
|
#![feature(const_option)]
|
||||||
#![feature(trait_alias)]
|
#![feature(trait_alias)]
|
||||||
#![feature(ptr_alignment_type)]
|
#![feature(ptr_alignment_type)]
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(if_let_guard)]
|
#![feature(if_let_guard)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(result_option_inspect)]
|
|
||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
#![recursion_limit = "512"] // For rustdoc
|
#![recursion_limit = "512"] // For rustdoc
|
||||||
|
|
|
@ -1079,8 +1079,6 @@ impl<T> Option<T> {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(result_option_inspect)]
|
|
||||||
///
|
|
||||||
/// let v = vec![1, 2, 3, 4, 5];
|
/// let v = vec![1, 2, 3, 4, 5];
|
||||||
///
|
///
|
||||||
/// // prints "got: 4"
|
/// // prints "got: 4"
|
||||||
|
@ -1090,11 +1088,8 @@ impl<T> Option<T> {
|
||||||
/// let x: Option<&usize> = v.get(5).inspect(|x| println!("got: {x}"));
|
/// let x: Option<&usize> = v.get(5).inspect(|x| println!("got: {x}"));
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "result_option_inspect", issue = "91345")]
|
#[stable(feature = "result_option_inspect", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn inspect<F>(self, f: F) -> Self
|
pub fn inspect<F: FnOnce(&T)>(self, f: F) -> Self {
|
||||||
where
|
|
||||||
F: FnOnce(&T),
|
|
||||||
{
|
|
||||||
if let Some(ref x) = self {
|
if let Some(ref x) = self {
|
||||||
f(x);
|
f(x);
|
||||||
}
|
}
|
||||||
|
|
|
@ -835,8 +835,6 @@ impl<T, E> Result<T, E> {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(result_option_inspect)]
|
|
||||||
///
|
|
||||||
/// let x: u8 = "4"
|
/// let x: u8 = "4"
|
||||||
/// .parse::<u8>()
|
/// .parse::<u8>()
|
||||||
/// .inspect(|x| println!("original: {x}"))
|
/// .inspect(|x| println!("original: {x}"))
|
||||||
|
@ -844,7 +842,7 @@ impl<T, E> Result<T, E> {
|
||||||
/// .expect("failed to parse number");
|
/// .expect("failed to parse number");
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "result_option_inspect", issue = "91345")]
|
#[stable(feature = "result_option_inspect", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn inspect<F: FnOnce(&T)>(self, f: F) -> Self {
|
pub fn inspect<F: FnOnce(&T)>(self, f: F) -> Self {
|
||||||
if let Ok(ref t) = self {
|
if let Ok(ref t) = self {
|
||||||
f(t);
|
f(t);
|
||||||
|
@ -858,8 +856,6 @@ impl<T, E> Result<T, E> {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(result_option_inspect)]
|
|
||||||
///
|
|
||||||
/// use std::{fs, io};
|
/// use std::{fs, io};
|
||||||
///
|
///
|
||||||
/// fn read() -> io::Result<String> {
|
/// fn read() -> io::Result<String> {
|
||||||
|
@ -868,7 +864,7 @@ impl<T, E> Result<T, E> {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "result_option_inspect", issue = "91345")]
|
#[stable(feature = "result_option_inspect", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn inspect_err<F: FnOnce(&E)>(self, f: F) -> Self {
|
pub fn inspect_err<F: FnOnce(&E)>(self, f: F) -> Self {
|
||||||
if let Err(ref e) = self {
|
if let Err(ref e) = self {
|
||||||
f(e);
|
f(e);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue