modify ArraySize to allow for arbitrary size support by third parties#81
modify ArraySize to allow for arbitrary size support by third parties#81conradludgate wants to merge 5 commits intoRustCrypto:masterfrom
Conversation
|
The invariant checker produces errors like Which is a bit of soup - but the text "ArraySize invariant violated" does appear pretty early, also listing |
|
For convenience, it might make sense to introduce |
| /// [`Unsigned::USIZE`]. Breaking this requirement will cause undefined behavior. | ||
| /// | ||
| /// NOTE: This trait is effectively sealed and can not be implemented by third-party crates. | ||
| /// It is implemented only for a number of types defined in [`typenum::consts`]. | ||
| pub unsafe trait ArraySize: Unsigned { |
There was a problem hiding this comment.
We use Unsigned::USIZE quite a bit, FWIW. I guess all of these usages would hypothetically have to change to ArraySize::Size::USIZE
There was a problem hiding this comment.
Yeah, that goes for my follow up suggestion of adding the convenience const. Although you do run into ambiguities then
|
So, I think something like this is interesting and something we should probably explore, but I worry about including it in the initial I'd like to keep this PR open, but I think we should skip it for |
|
My hope is |
I had this idea on discord to allow for third party crates to provide their own sizes. It means that
ArrayN<T, N>no longer is guaranteed to always work, but it still unblocks users with odd sized arrays such that they canunsafe implArraySize themselves.This also provides a best-effort invariant check that can catch wrong impls at compile time.
I appreciate if this design is undesirable, but I feel like #66 & #79 will be a never ending issue otherwise.