arraystring icon indicating copy to clipboard operation
arraystring copied to clipboard

use stabilized const generics instead of typenum

Open joseluis opened this issue 3 years ago • 4 comments

I wonder whether it'd be possible to substitute the typenum crate with the subset of const generics stabilized since Rust 1.51.

joseluis avatar Mar 11 '22 15:03 joseluis

The main hurdle I see is that the new const SIZE parameter must be usize since it can't be casted later to u8, so if there has to be a 255 limit it may have to be checked dynamically.

joseluis avatar Mar 11 '22 16:03 joseluis

The main problem of using arrays of const generic size, is that we must use usize everywhere, since casting from the generic argument is not allowed yet. That in turn increases the minimum size of ArrayString from 1 byte to 4 bytes in 64-bit systems. 16 bytes minimum.

The crate would therefore become less useful for small sized static strings, which I believe is the most important usecase.

I'm closing this. Until the necessary ability to cast const generic attributes arrives to stable I don't think there's a better solution that the current one.

joseluis avatar Mar 11 '22 21:03 joseluis

Somehow I only got notified about this issue today.

The maximum size is not a restriction and I'm open to those changes. But honestly, I haven't put a thought into this crate in a couple of years.

So if you can provide a PR with the changes I'm willing to review and accept it.

typenum and having to manually implement the trait for each of its types slows compilation down heavily, so removing it would be great.

paulocsanz avatar Dec 08 '22 16:12 paulocsanz

Ok, i did suggest something but it depended on generic const expr which is still unstable. Even if the size is > 255, all operation sizes are runtype checked anyway so if N > 255 it's just gonne fail at runtime like if it was N = 255.

Wicpar avatar Dec 08 '22 16:12 Wicpar