Closed
Description
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.