-
Notifications
You must be signed in to change notification settings - Fork 135
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
Blanket impl
for Real
trait prevents parameterized implementations.
#49
Comments
FWIW, I think the blanket implementation makes sense in context, but it is unfortunate that it prevents you from being generic. Now we have If we were to redesign this (in a breaking change), it would probably be something like
I think you could keep your parameterized impl for |
Ah, I see. I discovered the trait when I attempted to upgrade to
That sounds more ideal to me. Are there any plans to move towards a model like this in a future release?
Whoops, you're right. I would only need one-off implementations of |
Sure, there are informal plans, right here in this discussion. 😉 I've added this issue to #47. I fear it will be a nightmare to ever actually making breaking changes, but we can at least track ideas. In the meantime I'm going to close this issue as postponed, but feel free to continue the discussion if you think of more. |
I'm working on stabilizing a crate for constraints and total orderings of floating-point types. My crate integrates with num-traits, and has introduced subsets of the
Float
trait:Encoding
,Infinite
,Nan
, andReal
. The0.2.*
series of num-traits introduces aReal
trait of its own, which I would prefer to use instead, but the blanketimpl<T> Real for T where T: Float
makes this difficult. See this issue.I know this is a long shot, since this would likely involve breaking changes, but is there any chance this
impl
and the relationship betweenReal
andFloat
could be reconsidered? Just a few thoughts:Real
does not really behave as a subset given the blanket implementation. Users either implementReal
xorFloat
, rather than implementingReal
and any additional traits to satisfyFloat
. That relationship seems a bit backwards to me.Real
andFloat
. In my crate, this is a problem, because I implement both based on constraints on a wrapped typeT
. Attempting an implementation ofFloat
will always clash with an implementation ofReal
regardless of the constraints. This is the difficulty I'm referencing in the title of this issue.My guess is that the second point will almost always be a problem for parameterized types (i.e., wrappers) that may want to implement
Float
and/orReal
.The most obvious workaround for my crate is to remove the parameterized
impl
s forReal
andFloat
and duplicate a lot of code to implement them for the concrete type definitions that the crate re-exports. I can reduce duplication with a macro, but it makes the code more fragile, because type definitions that should pick up such implementations based on the input types alone would no longer get them implicitly.Thanks for taking a look at this. Thoughts?
The text was updated successfully, but these errors were encountered: