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
Currently, generic integers can't be used with hashmaps (which by extension means that they can't either be used with, for example, .unique() from itertools). Give the following code a whirl:
error[E0277]: the trait bound `N:Hash` is not satisfied
|
| .collect::<HashMap<N,N>>()
| ------- ^^^^^^^^^^^^^ the trait `Hash` is not implemented for `N`, which is required by `HashMap<N,N>:
|
= note:required for `HashMap<N,N>` to implement `FromIterator<(N,N)>`
note: required by a bound in `std::iter::Iterator::collect`
All of the standard types that PrimInt is implemented for implement Hash (which is why it makes sense for it to be a part of PrimInt), so this is only a breaking change if it's in scope for the API to implement PrimInt (which I wouldn't guessed it is based on the name, but I suppose it might be?).
It's possible to work around this issue by manually adding the trait bound:
But that's highly boilerplatitudinous, and bubbles up through anything that wants to call the function. It'd be wonderful to be able to comfortably write generic code for different number types in this area as well!
The text was updated successfully, but these errors were encountered:
so this is only a breaking change if it's in scope for the API to implement PrimInt (which I wouldn't guessed it is based on the name, but I suppose it might be?).
Yes it is, and there are real implementations in the wild, e.g. bnum. That example does also implement Hash, and probably most do, but we can't really assume that.
Slightly less boilerplate is to create your own extended trait with a blanket implementation:
Great to know! Alright, now that it's on your radar, I'll close this issue – I suppose it should be added to #47 “Tracking issue for potential breaking changes”, right?
Currently, generic integers can't be used with hashmaps (which by extension means that they can't either be used with, for example,
.unique()
fromitertools
). Give the following code a whirl:It raises the following compiler error:
All of the standard types that
PrimInt
is implemented for implementHash
(which is why it makes sense for it to be a part ofPrimInt
), so this is only a breaking change if it's in scope for the API to implementPrimInt
(which I wouldn't guessed it is based on the name, but I suppose it might be?).It's possible to work around this issue by manually adding the trait bound:
But that's highly boilerplatitudinous, and bubbles up through anything that wants to call the function. It'd be wonderful to be able to comfortably write generic code for different number types in this area as well!
The text was updated successfully, but these errors were encountered: