I'm trying to define a trait with an associated type. I also want the associated type to implement Iterator with its Item associated type implementing AsRef<str>.
While I know how to do it for a function or for a concrete Iterator::Item type, I can't come up with a clear and concise solution for the original case.
Thanks to the helpful error messages, my compiling solution is:
trait Note
where
<<Self as Note>::FieldsIter as Iterator>::Item: AsRef<str>,
{
type FieldsIter: Iterator;
//other fields and methods omitted
}
The ugly where clause makes me think that there should be a better way.
This doesn't compile since Item: AsRef<str> is an illegal construction:
trait Note {
type FieldsIter: Iterator<Item: AsRef<str>>;
//other fields and methods omitted
}
This fails since impl is not allowed here:
trait Note {
type FieldsIter: Iterator<Item = impl AsRef<str>>;
//other fields and methods omitted
}
This doesn't compile since I want Iterator::Item to implement a certain trait, not to be a concrete type.
trait Note {
type FieldsIter: Iterator<Item = AsRef<str>>;
//other fields and methods omitted
}