-
Notifications
You must be signed in to change notification settings - Fork 23
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 const getter for Copy types #126
Comments
Addition: I have the feeling that it would be hard doing something special just for Copy types. If this is too hard or even impossible, adding the const getter just to integers and floating point wrappers would be the alternative - that would cover most of the use cases I guess. |
Here's a prototypical implementation that adds |
@helgoboss Hi, thanks for your report! I think it's partially overlaps with #35 The problem with adding new method So I'd prefer rather option A, meaning implementing |
Ok, I understand. I hope to open a PR soon. |
I want to propose optionally adding a const getter method to newtypes that wrap a
Copy
value.Motivation
Given the following newtype:
(Side note: Being able to call
Self::new_unchecked
from a const context needs this)Now I would like to do things like this:
Above code is currently not possible because
into_inner()
is notconst
:Thoughts
Just making it
const
in general unfortunately doesn't work. Because it takesself
by value (which is the correct choice for a method of this name). And that fails to compile if the wrapped type is heap-allocated ("the destructor for this type cannot be evaluated in constant functions").I see 2 possibilities.
a) Making
into_inner
const, but only for Copy typesb) Introducing a separate const
get
method, but only for Copy typesPersonally, I prefer b. There are quite many examples in the standard library where a wrapper exposes its wrapped
Copy
value in aget
method, so it appears to be a good practice. But ultimately I don't mind.Do you think it's somehow possible to do a or b? Just for
Copy
types? And if yes, would you consider it? I would be happy to write a PR.The text was updated successfully, but these errors were encountered: