mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 06:22:00 +00:00
Consolidate impl Result<&T, E>
This commit is contained in:
parent
b2df61fa9f
commit
e63e2680da
@ -1493,7 +1493,7 @@ impl<T, E> Result<T, E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy, E> Result<&T, E> {
|
||||
impl<T, E> Result<&T, E> {
|
||||
/// Maps a `Result<&T, E>` to a `Result<T, E>` by copying the contents of the
|
||||
/// `Ok` part.
|
||||
///
|
||||
@ -1508,9 +1508,33 @@ impl<T: Copy, E> Result<&T, E> {
|
||||
/// assert_eq!(copied, Ok(12));
|
||||
/// ```
|
||||
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
|
||||
pub fn copied(self) -> Result<T, E> {
|
||||
pub fn copied(self) -> Result<T, E>
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
self.map(|&t| t)
|
||||
}
|
||||
|
||||
/// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
|
||||
/// `Ok` part.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(result_cloned)]
|
||||
/// let val = 12;
|
||||
/// let x: Result<&i32, i32> = Ok(&val);
|
||||
/// assert_eq!(x, Ok(&12));
|
||||
/// let cloned = x.cloned();
|
||||
/// assert_eq!(cloned, Ok(12));
|
||||
/// ```
|
||||
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
|
||||
pub fn cloned(self) -> Result<T, E>
|
||||
where
|
||||
T: Clone,
|
||||
{
|
||||
self.map(|t| t.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy, E> Result<&mut T, E> {
|
||||
@ -1533,26 +1557,6 @@ impl<T: Copy, E> Result<&mut T, E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Clone, E> Result<&T, E> {
|
||||
/// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
|
||||
/// `Ok` part.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(result_cloned)]
|
||||
/// let val = 12;
|
||||
/// let x: Result<&i32, i32> = Ok(&val);
|
||||
/// assert_eq!(x, Ok(&12));
|
||||
/// let cloned = x.cloned();
|
||||
/// assert_eq!(cloned, Ok(12));
|
||||
/// ```
|
||||
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
|
||||
pub fn cloned(self) -> Result<T, E> {
|
||||
self.map(|t| t.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Clone, E> Result<&mut T, E> {
|
||||
/// Maps a `Result<&mut T, E>` to a `Result<T, E>` by cloning the contents of the
|
||||
/// `Ok` part.
|
||||
|
Loading…
Reference in New Issue
Block a user