Stabilize as_deref and as_deref on Result
This commit is contained in:
parent
07575286b8
commit
c25f25f7f1
8 changed files with 5 additions and 15 deletions
|
@ -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())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue