Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: generic over the underlying vector like container #31

Open
Pr0methean opened this issue Mar 21, 2024 · 1 comment
Open

Comments

@Pr0methean
Copy link

Pr0methean commented Mar 21, 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]>.

@rustonaut
Copy link
Owner

rustonaut commented Mar 23, 2024

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 rustonaut changed the title Feature request: generify over Index<usize> Feature request: generic over the underlying vector like container Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants