-
Notifications
You must be signed in to change notification settings - Fork 12
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
Support more integer types #63
base: master
Are you sure you want to change the base?
Conversation
In case you are not familiar with sealed traits: https://predr.ag/blog/definitive-guide-to-sealed-traits-in-rust/ |
Edit: Found a good solution. |
2c8ea89
to
27f53da
Compare
27f53da
to
41ef31d
Compare
This is pretty neat! Another way forward might be https://doc.rust-lang.org/reference/items/associated-items.html#associated-types-container-example or https://doc.rust-lang.org/reference/items/generics.html to have a loose function for index calculations. People have started comming back from the holidays now at work so have less time to might take some time to answer. Thank you for your patience! |
For demonstration purposes I only added
That would drastically increase the visible API. On implementation side we can handle this using macros. But still, the API would be huge. And I think it's also worse for compilation speed. stdlib did the same with with non-zero integers, e.g.
We could use conditional compilation: #[cfg(target_pointer_width = "32")]
impl_sealed_int! {
usize,
4294967291usize // Largest prime for u32
}
#[cfg(target_pointer_width = "64")]
impl_sealed_int! {
usize,
11400714819323198549usize // Largest prime for u64
}
This might reduce the impact of having different types
I don't understand this one.
No problem and thanks for the feedback! How do you think we should proceed with this topic? Implementation wise I'm happy with the current PR (but some polishing is still necessary). From an API perspective I would prefer If you have the strong feeling that another approach is worth to be investigated, then I'll try it. This PR is not really urgent for me, so I would proceed with the performance topic and continue this PR as soon as you made a decision. |
My bad, missed the anchor in the link. Meant const generics: https://doc.rust-lang.org/reference/items/generics.html#const-generics |
This feature would be nice for us rust-lang/rfcs#3686 :p |
Yeah, that one would save a lot of work :) |
Add support for more integer types. Actually it was pretty easy.
I introduce a new sealed trait that is used by
IntMap
:The most complicated part was implementing the optional serde support. I found an ugly solution, but it's just an implementation detail that we could change later.I need to change the type of
mod_mask
fromu64
tousize
. But I'm think that's okay? We need to be careful here.I think (but I'm not 100% sure) that this PR does not introduce any breaking changes.
IntMap
has now a default type parameter and new constructors:Vec
from stdlib does something similar:However, if you prefer a breaking change we could remove the default, swap the type parameters and use the more common names
K
andV
:Closes #61