Open Pr0methean opened 8 months ago
I think you are misunderstanding what this crate does.
It doesn't just provide a new-type you check the len>1 invariant on construction (you can always do that with just a few lines of code).
It provides a full Vec
/SmallVec
functionality with the len>1 variant, i.e. as far as viable (and I didn't overlook it):
[T]
/&mut [T]
methods Vec
has, too&Vec<T>
methods&mut Vec<T>
methods which do not decrease the length are proxied (e.g. the dedup methods)&mut Vec<T>
methods which do change the length have a alternative implementation which error if the length would be changed to 0 (e.g. retain
){try_,}mapped{_ref,_mut}
)And same for SmallVec
.
As you might have noticed most of this functionality doesn't apply to Box<[T]>
or &[T]
at all.
And at least when I wrote that crate using generics wasn't very feasible (probably is different by now). But even if it's feasible it's not convenient, i.e. requires a bunch of custom Traits and getting all the ~55 trait implementations right (as in exactly the same behavior as now) isn't trivial.
Furthermore I don't want to release a v2 of this crate as it would be annoying for anyone using Vec1
in a public API (which might be possible by making Vec1
a type alias, but can be tricky).
Oh and String
has completely different APIs and most times "non zero" constraints on Strings
are not "non zero unicode code points" but non zero printable characters and similar.
Making this struct's inner type a generic parameter would mean it could also be used with String, boxed slices, and borrowed slices.
If Index doesn't provide enough features, an alternative would be AsRef<[T]>.