refactor: params extra types are zero values not nil pointers by default #13
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.
Why this should be merged
Adds support for type-safe setting of
ChainConfig
andRules
extras via theExtraPayloadGetter
, which can now return pointers. This is demonstrated to work with zero-values of both types.How this works
I suspect that zero-value extras via
x := new(ChainConfig)
orvar x ChainConfig
have always worked this way, but the behaviour is now locked in with a test that also demonstrates shallow copying.Note
As the extras are wrapped in a
*pseudo.Type
, shallow copying only copies the address of the wrapper even if the registered type is not a pointer.Modification via pointers is achieved by extending the
pseudo
package to allow for "addressing" via the newPointerTo()
function. This is then exposed via theExtraPayloadGetter.PointerFromChainConfig() *C
andPointerFromRules() *R
methods to provide type safety to external users. The guarantees of correctness that avoidMustNewPointer()
panicking are the same as those for the originalFromChainConfig()
andFromRules()
methods.The other changes to
C
andR
plumbing (i.e never using*C
and*R
) were to clean up a code smell; this made the rest of this PR much easier to reason about. I relaxed the constraint onC
andR
being structs, allowing for pointers to structs, also because it's a smell (that I think can actually be removed entirely but in another PR).How this was tested
New unit test for
pseudo.PointerTo()
and integration test forExtraPaloadGetter.PointerFrom{ChainConfig,Rules}()
.