Skip to content

Add a new std::mem::copied function. #78

@jyn514

Description

@jyn514

Proposal

Add a new std::mem::copied function.

Problem statement, Motivation, use-cases

Right now if you want to pass a function pointer to a combinator, you need to define a new closure. This is a very small paper cut, but it comes up quite frequently. Having a named function reduces the line noise and makes the code easier to read.

let result_from_ffi_function: Result<(), &i32> = Err(&1);
let result_copied: Result<(), i32> = result_from_ffi_function.map_err(|x| *x);

Solution sketches

// core::mem
pub fn copied<T: Copy>(x: &T) -> T { *x }

The new function will make the code simpler:

use std::mem::copied;
let result_copied: Result<(), i32> = result_from_ffi_function.map_err(copied);

Links and related work

This mirrors core::mem::drop and core::mem::take.

rust-lang/rust#95534, rust-lang/rust#98262, rust-lang/rust#100006

What happens now?

This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard libraries

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions