Make @service
only define a module once
#690
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently,
@service
defines a module every time it's called. That works fine but the downside is that you get module redefinition warnings if you happen to call@service
again. The most plausible reason why one would want to redefine the module would be to enable/disable particular features in some region of code. To facilitate that use case while avoiding redefinition warnings, we can make@service
check for an existing module, define one if it can't find one, and if it can then modify the feature set associated with the module in place. With this change,@service S3
(e.g.) effectively expands to:The
set_features!
call uses the features specified in the macro call as keyword arguments. No arguments uses defaults. Notably this design requires thatFeatureSet
be made mutable, which seems fine IMO.