I would like to implement my own generic container, and this is the fragment of a trait I am using:
pub trait MyVec
where
Self: Default + Clone + IntoIterator,
Self: std::iter::FromIterator<<Self as IntoIterator>::Item>,
{
fn get(self: &Self, index: usize) -> <Self as IntoIterator>::Item;
// many other methods are omitted.
}
Is it possible to introduce a new computed type variable so that I can avoid typing <Self as IntoIterator>::Item
everywhere? A simple type Item = <Self as IntoIterator>::Item
does not work because that is an associated type that could potentially be overridden. Using a type parameter as MyVec<I>
does not work either as I do not want to implement this trait with different I
types for the same struct, and it also causes problem when writing generic code later. Any recommendations?