I want to implement FromIterator for my local type Series. The problem is instantiation of Series is fallible, so FromIterator::from_iter must return Result.
My attempt:
impl<T: PartialOrd> FromIterator<T> for Result<Series<T>, Error<T>> {
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
Self::try_new(iter.into_iter().collect::<Vec<T>>())
}
}
Results in:
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> src/series.rs:58:6
|
58 | impl<T: PartialOrd> FromIterator<T> for Result<Series<T>, Error<T>> {
| ^ type parameter `T` must be used as the type parameter for some local type
|
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
= note: only traits defined in the current crate can be implemented for a type parameter
But T is being used in Series<T>, which is a local type. So I'm struggling to see what the problem is. Is it because the local type isn't "top-level"? (because Result is enclosing Series)