-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a new std::mem::copied
function.
#78
Comments
Note: the actual proposal here is to rename the unstable Background: this is a function which simply takes a The motivation for making it a const fn is that you can already dereference a The motivation for the rename to I think the main thing I'd wonder about this is if there's some module besides Footnotes
|
Note that copied() only exists for Iterator and Option; for it to be as useful as the standalone function there would need to be a Result::copied and Result::copied_err. And that still wouldn't support custom data structures or enums. I agree mem::copied seems a little confusing, but not sure a better name for it ... |
Copying from rust-lang/rust#95534 (comment): I think this might really want to be something like pub trait Clone {
fn clone(&self) -> Self; // as today
#[sealed]
fn copy(&self) -> Self where Self: Copy { *self }
} And I think someone might be working on an RFC for such an attribute... |
@scottmcm This has the disadvantage that you can't |
But it then has the advantage that it is always in scope, since * Actually, it isn't quite always, since types can have a |
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
👍 for the rename and constification. (There's still a fair bit of debate about whether we want to stabilize this function, but we all agreed that the new name is better.) |
Proposal
Add a new
std::mem::copied
function.Problem statement, Motivation, use-cases
Right now if you want to pass a function pointer to a combinator, you need to define a new closure. This is a very small paper cut, but it comes up quite frequently. Having a named function reduces the line noise and makes the code easier to read.
Solution sketches
The new function will make the code simpler:
Links and related work
This mirrors
core::mem::drop
andcore::mem::take
.rust-lang/rust#95534, rust-lang/rust#98262, rust-lang/rust#100006
What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.
The text was updated successfully, but these errors were encountered: