File tree 1 file changed +22
-0
lines changed
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 {
964
964
#[ cfg_attr( not( test) , rustc_diagnostic_item = "mem_drop" ) ]
965
965
pub fn drop < T > ( _x : T ) { }
966
966
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
+
967
989
/// Interprets `src` as having type `&U`, and then reads `src` without moving
968
990
/// the contained value.
969
991
///
You can’t perform that action at this time.
0 commit comments