-
Notifications
You must be signed in to change notification settings - Fork 35
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
Option to make constructor const
#51
base: master
Are you sure you want to change the base?
Conversation
Could the constructor always be |
Good question. I was thinking of types like Maybe there are other edge cases to beware of though. |
Oh, bigger issue: |
Why is this an issue? |
Using
|
I see, thanks! How about we make |
Looking at https://github.com/nrc/derive-new#examples, So I think it's probably necessary to make it an option of some kind. |
I think that if there are no field annotations, then we can always generate a (The reason I'm digging into this is that in general I think |
I think that should work. It is potentially a backwards compatability issue though. (The Readme specifically mentions adding a new member without breaking comparability as a goal of the crate.) Adding a use of
What do you mean? It's difficult to the extent that the code is somewhat verbose, but it's certainly not impossible. The code in this PR works, for structs, except for the conflict when the I suppose this issue would be addressed using another attribute name, like |
AIUI, adding a new member would be backwards compatible as would adding
If there is a field with type
The conflict with |
Sorry to bring this one back from the dead, but have you considered that changing the field attribute is not the right move, since the "const" will need to be repeated every annotated field? Wouldn't it be better to create a new derive, which could be "new_const", that uses the same atributes but creates a const new. |
It's sometimes convenient for a constructor to be a
const fn
.Compiling the unit test here fails with:
Not sure how to solve that. I guess not using the same name
new
for both...I guess if that can be addressed, this should also have documentation, and work with enums. Anyway, I thought I might as well open a draft PR with the code I have for now.