-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Tracking Issue for core::mem::copy
#98262
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
If you have |
@eggyal it's the difference between (In this particular case, there's Option::copied, but there's not Result::copied_err or anything; and this is useful for custom types too) |
Why not make it const right away? pub const fn copy<T: Copy>(x: &T) -> T {
*x
} compiles on stable... |
Of course, this works if it's a free function; but would not (for now) if it's made an associated function on the |
i'm mildly concerned that std::mem::copy and std::ptr::copy both would exist but do very different sorts of things. Can we call this new function |
Hmm sure, copied seems fine. I do think that all the functions in std::ptr are kind of expected to deal with raw memory; I don't think it would be hard to tell them apart in practice. But I don't feel strongly. |
in an ideal world everything could be fully imported, so this helps the ideal. |
prior art: rust/compiler/rustc_middle/src/ty/query.rs Lines 109 to 113 in 7b8e2a5
|
I think this function should be marked |
Make `core::mem::copy` const cc rust-lang#98262, rust-lang/libs-team#78
Make `core::mem::copy` const cc rust-lang/rust#98262, rust-lang/libs-team#78
I feel this method while useful may be premature, specially we already have other solution like |
To throw my hat in the ring here, I actually ran into a helpful use case for this function today. Using the unstable iter_next_chunk api on an vector of u8s, I got a |
Uh oh!
There was an error while loading. Please reload this page.
Feature gate:
#![feature(mem_copy_fn)]
This is a tracking issue for
core::mem::copy
, which is a way - likemem::drop
- to copy a value without creating a new closure.Public API
Steps / History
core::mem::copy
to complementcore::mem::drop
. #95534Unresolved Questions
Copy
instead?The text was updated successfully, but these errors were encountered: