Add coercing versions of conversion functions #171
Merged
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.
These are variants of
.as
and.in
for bothQuantity
andQuantityPoint
. When we precede these with the "coerce" vocabularyword, they become forcing, ignoring the safety checks for truncation and
overflow.
This new syntax has two major advantages over the explicit-Rep version.
First, it makes the intent clearer. Second, it stops forcing users to
repeat the rep when they want the same rep they started with, which I
think is the usual case. (Thus, without these APIs, explicit-rep
obscures intent: one never knows whether the author wanted a cast, or
wanted to bypass the safety checks.)
It also unlocks another, later improvement: we will be able to extend
the safety checks to the explicit-rep versions! But we won't attempt
that for a while because that's a breaking change.
There may be other APIs that would benefit from using the "coerce"
vocabulary word instead of explicit-rep. However, we'll start with just
these, both because they're the overwhelmingly most common use case, and
because it gives us a chance to try out these ideas in practice for a
while.
To test this PR, I added new unit tests to cover all of the use cases.
I also rendered the docs locally and checked that the links worked as
intended.
Helps #122.