You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
through deref all [T]/&mut [T] methods Vec has, too
all &Vec<T> methods
all &mut Vec<T> methods which do not decrease the length are proxied (e.g. the dedup methods)
all &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)
all the standard utility traits (e.g. TryFrom<[T;N>, around 55 of them)
a small number of helper methods (mainly {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.
rustonaut
changed the title
Feature request: generify over Index<usize>
Feature request: generic over the underlying vector like container
Mar 23, 2024
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]>.
The text was updated successfully, but these errors were encountered: