mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-23 21:23:20 +00:00
Stabilize as_deref and as_deref on Result
This commit is contained in:
parent
07575286b8
commit
c25f25f7f1
@ -1145,7 +1145,6 @@ impl<T, E: Into<!>> Result<T, E> {
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "inner_deref", issue = "50264")]
|
||||
impl<T: Deref, E> Result<T, E> {
|
||||
/// Converts from `Result<T, E>` (or `&Result<T, E>`) to `Result<&<T as Deref>::Target, &E>`.
|
||||
///
|
||||
@ -1155,7 +1154,6 @@ impl<T: Deref, E> Result<T, E> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(inner_deref)]
|
||||
/// let x: Result<String, u32> = Ok("hello".to_string());
|
||||
/// let y: Result<&str, &u32> = Ok("hello");
|
||||
/// assert_eq!(x.as_deref(), y);
|
||||
@ -1164,13 +1162,12 @@ impl<T: Deref, E> Result<T, E> {
|
||||
/// let y: Result<&str, &u32> = Err(&42);
|
||||
/// assert_eq!(x.as_deref(), y);
|
||||
/// ```
|
||||
#[stable(feature = "inner_deref", since = "1.47.0")]
|
||||
pub fn as_deref(&self) -> Result<&T::Target, &E> {
|
||||
self.as_ref().map(|t| t.deref())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[unstable(feature = "inner_deref", issue = "50264")]
|
||||
impl<T: DerefMut, E> Result<T, E> {
|
||||
/// Converts from `Result<T, E>` (or `&mut Result<T, E>`) to `Result<&mut <T as DerefMut>::Target, &mut E>`.
|
||||
///
|
||||
@ -1180,7 +1177,6 @@ impl<T: DerefMut, E> Result<T, E> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(inner_deref)]
|
||||
/// let mut s = "HELLO".to_string();
|
||||
/// let mut x: Result<String, u32> = Ok("hello".to_string());
|
||||
/// let y: Result<&mut str, &mut u32> = Ok(&mut s);
|
||||
@ -1191,6 +1187,7 @@ impl<T: DerefMut, E> Result<T, E> {
|
||||
/// let y: Result<&mut str, &mut u32> = Err(&mut i);
|
||||
/// assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y);
|
||||
/// ```
|
||||
#[stable(feature = "inner_deref", since = "1.47.0")]
|
||||
pub fn as_deref_mut(&mut self) -> Result<&mut T::Target, &mut E> {
|
||||
self.as_mut().map(|t| t.deref_mut())
|
||||
}
|
||||
|
@ -26,7 +26,6 @@
|
||||
#![feature(test)]
|
||||
#![feature(trusted_len)]
|
||||
#![feature(try_trait)]
|
||||
#![feature(inner_deref)]
|
||||
#![feature(slice_internals)]
|
||||
#![feature(slice_partition_dedup)]
|
||||
#![feature(int_error_matching)]
|
||||
|
@ -24,7 +24,6 @@
|
||||
#![feature(decl_macro)]
|
||||
#![feature(extern_types)]
|
||||
#![feature(in_band_lifetimes)]
|
||||
#![feature(inner_deref)]
|
||||
#![feature(negative_impls)]
|
||||
#![feature(optin_builtin_traits)]
|
||||
#![feature(restricted_std)]
|
||||
|
@ -5,7 +5,6 @@
|
||||
#![feature(bool_to_option)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(decl_macro)]
|
||||
#![feature(inner_deref)]
|
||||
#![feature(nll)]
|
||||
#![feature(or_patterns)]
|
||||
#![feature(proc_macro_internals)]
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(inner_deref)]
|
||||
|
||||
fn main() {
|
||||
let _result = &Ok(42).as_deref();
|
||||
//~^ ERROR no method named `as_deref` found
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0599]: no method named `as_deref` found for enum `std::result::Result<{integer}, _>` in the current scope
|
||||
--> $DIR/result-as_deref.rs:4:27
|
||||
--> $DIR/result-as_deref.rs:2:27
|
||||
|
|
||||
LL | let _result = &Ok(42).as_deref();
|
||||
| ^^^^^^^^ help: there is an associated function with a similar name: `as_ref`
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(inner_deref)]
|
||||
|
||||
fn main() {
|
||||
let _result = &mut Ok(42).as_deref_mut();
|
||||
//~^ ERROR no method named `as_deref_mut` found
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0599]: no method named `as_deref_mut` found for enum `std::result::Result<{integer}, _>` in the current scope
|
||||
--> $DIR/result-as_deref_mut.rs:4:31
|
||||
--> $DIR/result-as_deref_mut.rs:2:31
|
||||
|
|
||||
LL | let _result = &mut Ok(42).as_deref_mut();
|
||||
| ^^^^^^^^^^^^ help: there is an associated function with a similar name: `as_deref_err`
|
||||
| ^^^^^^^^^^^^ method not found in `std::result::Result<{integer}, _>`
|
||||
|
|
||||
= note: the method `as_deref_mut` exists but the following trait bounds were not satisfied:
|
||||
`{integer}: std::ops::DerefMut`
|
||||
|
Loading…
Reference in New Issue
Block a user