You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This replaces the reflect based field selector/setter, and dynamic
function generation/calling - with generic type constraints and
option functions which utilize interfaces.
The previous code worked, but relied on strings to be used to reference
field values that were common across different types (that typically
inherited from each other). If a field name or shape of a struct ever
changed, this could cause a panic at runtime if the relevant option
function's constructor was not also updated.
Now, field selection is based around setter methods, and assignment is
handled by generic closure generators. If structures change, it
shouldn't cause issues, and if it would, the program will fail to
compile altogether rather than panic at runtime.
The cost is requiring field setters, but seems worth the change as
things can be further refactored in the future with more ease (compared
to the reflection approach) if better solutions become apparent.
0 commit comments