make automatic length detection feature-gated #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I think that the automatic length detection is cool, but I'm not sure how actually useful it is. As it is, the following code doesn't compile:
Worse, the error message is confusing:
I just feel like the automatic length detection is reinventing the wheel whilst making code which used to compile break. Personally, I'd rather it just default to a u32, and you can specify a smaller type if your space requirements are particularly confining (or if u32::MAX is too small), rather than having code that used to compile not compile in a vast majority of circumstances.
There are defaults for 23/256 possible u8 lengths. The whole point of the automatic length detection is to save the user having to write
when in a vast majority of circumstances (assuming even distribution of lengths, thats ~91% of u8s, ~99.98% of u16s, ~99.999999993% of u32s, and some ridiculous number for u64 that my calculator won't display) the user will have to write it anyway. It just seems like there's not much point, and we are better off leaving performance to be opt-in.
In nightly, we can use #![feature(specialization)] to allow a default implementation with u32, solving the problem and giving us the best of both worlds - but it should be gated behind a nightly feature, which is what I've done here.