File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -964,6 +964,28 @@ pub const fn replace<T>(dest: &mut T, src: T) -> T {
964964#[ cfg_attr( not( test) , rustc_diagnostic_item = "mem_drop" ) ]
965965pub fn drop < T > ( _x : T ) { }
966966
967+ /// Bitwise-copies a value.
968+ ///
969+ /// This function is not magic; it is literally defined as
970+ /// ```
971+ /// pub fn copy<T: Copy>(x: &T) -> T { *x }
972+ /// ```
973+ ///
974+ /// It is useful when you want to pass a function pointer to a combinator, rather than defining a new closure.
975+ ///
976+ /// Example:
977+ /// ```
978+ /// #![feature(mem_copy_fn)]
979+ /// use core::mem::copy;
980+ /// let result_from_ffi_function: Result<(), &i32> = Err(&1);
981+ /// let result_copied: Result<(), i32> = result_from_ffi_function.map_err(copy);
982+ /// ```
983+ #[ inline]
984+ #[ unstable( feature = "mem_copy_fn" , issue = "98262" ) ]
985+ pub fn copy < T : Copy > ( x : & T ) -> T {
986+ * x
987+ }
988+
967989/// Interprets `src` as having type `&U`, and then reads `src` without moving
968990/// the contained value.
969991///
You can’t perform that action at this time.
0 commit comments