-
Notifications
You must be signed in to change notification settings - Fork 620
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
Allow FieldsOf
to provide a pointer type
#208
Comments
Seems reasonable to me. One option would be to make Another option would be to add some syntax, e.g., @shantuo @zombiezen thoughts? |
The issue with |
Option 1) SGTM, which is what we do in the struct provider now. |
(Sorry, meant to get to this over the weekend but I fell ill.) I think either of the options is fine, but I think that is important that the pointer variant is only allowed if the provided struct is of a pointer type. So this would work: // Provides *UserConfig given a *Config
wire.FieldsOf(new(*Config), "UserConfig") but this shouldn't: // Does not provide *UserConfig.
// Provides a UserConfig given a Config.
wire.FieldsOf(new(Config), "UserConfig") Reason being, it would be incorrect for the address of the field to be nondeterministic (addressing from a temporary), versus having a stable address expression. |
Good point @zombiezen . I'll send a PR to limit the pointer-to-field to cases where the struct type is a pointer to a struct. |
Is your feature request related to a problem? Please describe.
I am trying to wire a non-pointer field from a struct to a provider which requires a pointer of the same type
Consider the following
I am unable to wire the
UserConfig
field in myConfig
for theInitializeUser
provider without writing a wrapper provider by hand.Describe the solution you'd like
FieldsOf
should provide both a non-pointer and a pointer type of that field. This seems to already be done today by theStruct Providers
as per the documentation. It would be useful (and consistent) ifFieldsOf
would do the sameDescribe alternatives you've considered
The alternative it to write your own simple wrapper provider such as
The text was updated successfully, but these errors were encountered: