Function core::mem::copy

source ·
pub const fn copy<T: Copy>(x: &T) -> T
🔬This is a nightly-only experimental API. (mem_copy_fn #98262)
Expand description

Bitwise-copies a value.

This function is not magic; it is literally defined as

pub fn copy<T: Copy>(x: &T) -> T { *x }

It is useful when you want to pass a function pointer to a combinator, rather than defining a new closure.


use core::mem::copy;
let result_from_ffi_function: Result<(), &i32> = Err(&1);
let result_copied: Result<(), i32> = result_from_ffi_function.map_err(copy);