Sized (or Sizeable) str, e.g. str<const N: usize>
Rust has str (where the type system loses size info) or [u8; N] (which loses utf-8 info.) I want size and utf-8, as for any "literal str" the compiler does know both.
This is to fix error handling in the next version of Stringlet. Currently my Froms illegally panic, if either size or utf-8 are violated. For dynamic data this should be TryFrom -> Result. But for &'literal str I resist so much ceremony. Here the compiler could already check that the size fits into [u8; N], while maintaining utf-8 well-formedness. (Besides: Result can’t be used in const.)
Is there already a way of achieving this? Or is there a plan for something like my fantasy optional str<const N: usize>?
For the harder part of the question: I have several kinds of Stringlet where shorter strings can be stored with padding. So actually I’d want something like str<0..256>. For this case I do already have a config trait implemented for each possible number. As I’m thinking of making things more flexible, I’d need to add even more such traits and impls. That’s rather cumbersome and possibly quite a drag on the trait resolver.
If we’re getting configurable ints, and they can generically parametrize T<const N: UInt<5..9>>([u8; N]), that might solve this.
Discussion in the ATmosphere