Skip to content

Add .cloned() method to Result? #50951

Closed
Closed
@novacrazy

Description

@novacrazy

It caught me off-guard that there isn't a .cloned() method for Result<&T, E>, yet there is one for Option<&T>.

I don't think this is a big enough feature to have a whole RFC for, even though I can do that if necessary, but it would be nice to have a .cloned() method like this:

impl<'a, T, E> Result<&'a T, E>
where
    T: Clone,
{
    #[inline]
    pub fn cloned(self) -> Result<T, E> {
        self.map(Clone::clone)
    }
}

and the equivalent mutable reference version.

However, if there is a reason why this is not already in place, I can understand. It simply feels a little awkward having to manually map Clone::clone in otherwise idiomatic code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions