RFC: Use marker types to improve ergonomics of mod fundamental #24
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.
Working through the nutation models, I now better understand the usage of the various fundamental arguments, and believe we can make a significant improvement to the ergonomics of these arguments than previous C libraries afford.
Problem
Different conventions define the same fundamental arguments differently for the same
bodies, but we lack a coherent way to represent this. For example, the mean longitude of the ascending node of the Moon is defined differently in the IERS2003 and MHB2000 conventions.
The set of traits currently defined and implemented in fundamental.rs is IERS 2003-only, but we don't want to define a new trait for each combination of conventions and argument, which will quickly get out of hand and lead to long, convoluted method names to avoid clashes when implemented on the same body.
Nor do we want to define a new body for each set of conventions – there are enough of them as it is.
Proposed solution
Following a recommendation in Rust for Rustaceans, we can define a marker type for
each convention, make the body generic over the marker, and implement the same trait for each marker.
The body remains zero-sized, its instances are constant, and there's no need to namespace fundamental arguments trait declarations.
This is also clearer for consumers of the Lox API, who no longer have to wonder why mod fundamental provides only IERS 03 fundamental args.
My recommendation, initially at least, is to limit the scope of these changes to mod fundamental – please read the code example from beginning to end 🙏
The provided example is limited to a single file, and isn't intended to reflect any proposed module structure.