On this page
Function std::mem::copy
pub const fn copy<T>(x: &T) -> T
where
T: Copy,
🔬This is a nightly-only experimental API. (
mem_copy_fn
#98262)
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.
Example:
#![feature(mem_copy_fn)]
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);
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/mem/fn.copy.html