Impl for Vec<T>, &[T] or any other contiguous collection?

Hi,
The current plan is to create a macro to generate the impls which will work.

I would like to know if there is a trick to make it work without a macro:
impl<T> Trait for Vec<T>
impl<T> Trait for &[T]
impl<T> Trait for [T;N] <- Not sure how to handle this one for arrays. What if the N is large ? I would create a macro for a macro that would generate every N at compile time.

I would like something like
impl<T> Trait for thisGroupOfCollection that would regroup everything to avoid writing as much as possible.

impl<T> Trait for &[T] is not sufficient because the Vec is not &Vec in the input.

Thanks!

Just use a generic N:

impl<T, const N: usize> Trait for [T; N] {}
4 Likes

If you're willing to add a generic to your trait, you could consider impl<C, T> Trait<T> for C where C: AsRef<[T]>

5 Likes

Thanks guys, both of you have given a very good solution for each part of my issue.
I will make this work.