-
Notifications
You must be signed in to change notification settings - Fork 31
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 @kw_only macro #147
base: master
Are you sure you want to change the base?
Add @kw_only macro #147
Conversation
Codecov Report
@@ Coverage Diff @@
## master #147 +/- ##
==========================================
- Coverage 93.42% 92.92% -0.50%
==========================================
Files 1 1
Lines 304 311 +7
==========================================
+ Hits 284 289 +5
- Misses 20 22 +2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
(Better add a test... done) |
`@kw_only` behaves the same as `@with_kw` but does not declare a default constructor when no inner constructor is found.
Please let me know if you have any concerns about merging this. |
Please let me know if there are any problems with this patch or if you would like to discuss the change. |
Sorry, I'll get to it. Thanks for your work! |
No need to apologize! Thanks for your work on the library and for taking a look at this patch. |
Hi! It looks like there's a conflict now, but also I found a problem with the approach used in this PR. An outer positional constructor appears to be a requirement when we want to have a type parameterised struct with a type parameter-free constructor (which necessarily includes keyword constructors). Since I want to hide positional constructors, I have figured out a new approach where we create a dummy type I realise the |
@kw_only
behaves the same as@with_kw
but does not declare a default constructor when no inner constructor is found.This is useful in occasions where you might like to declare a very generic outer constructor, as in the following example.
With
@with_kw
,Example(42 "blah")
would call the default inner constructor, whereas I would like for the outer constructor to be called in this case.I can think it may be somewhat desirable in other situations where we want the keyword constructor to be the only interface, such as when there are a lot of fields in a struct and we might like to freely add fields anywhere without changing the constructor interface.