-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add getters providing strongly typed Length values #461
base: main
Are you sure you want to change the base?
Conversation
There are a few other getters to add but I'd like to discuss the naming scheme before doing the rest of the work. |
For reference, I tinkered in a separate branch with another naming scheme that avoids the
That scheme looks nice in principle, in practice it make the ergonomics of working with scalars quite a bit worse. We end up having to sprinkle A subsequent commit implements Deref for Length in an attempt to make the sprinkling of So as far as A third option is to make the API as nice to use as possible at the expense of consistency, and keep the nicest names wherever we can. We would skip the prefix for getters where the value can be accessed directly as a scalar member (for example |
Ok, let's defer this until after the release, since it's not breaking. |
☔ The latest upstream changes (presumably #476) made this pull request unmergeable. Please resolve the merge conflicts. |
Any update? Edit: but actually it would also be nice to have it in more even types like all the accessors of Rect that currently return T directly. |
I'm still keen on adding strongly typed variants of methods that return scalars where it makes sense using the |
Sure |
We're interested in this feature in Servo, so if there is no opposition, we'd really like to land this. We're happy to continue the discussion about the name of these APIs, but otherwise these seem really useful. |
Fixes #396 and #388.
This PR adds strongly typed
Length
getters with a simple naming scheme: anything prefixed withget_
returns aLength<T, U>
, while unprefixed methods returning a scalar and direct scalar member accesses yieldT
directly.The main motivations behind this approach are:
v.x_typed()
and it was just too awkward to use so we removed it. I think thatget_
has less cognitive load and a long line of computation with lots of them is much easier to read than long lines with lots of*_typed
suffixes.