I'm working on implementing ECMAScript® 2023 Internationalization API Specification as traits and I can't figure out how to handle supported_locales_of
method.
Such method should accept a list of Locale
values, and return a filtered version of that list narrowed down based on some match criteria (availability of the locale).
I could do this with slices or lists, but I wanted to try to be a bit more precise and use an iterator. So, I want to accept an iterator, filter it, and return an iterator - kind of like a stream.
I currently have something like this:
// Mock of a Locale
#[derive(Clone)]
pub struct Locale {
language: String
}
/* TRAIT */
pub trait ListFormatType {
type Iter: Iterator<Item = Locale>;
fn supported_locales_of<I>(input: I) -> Self::Iter
where
I: IntoIterator<Item = Locale>;
}
struct ListFormat {}
impl ListFormatType for ListFormat {
type Iter = Iterator<Item = Locale>;
fn supported_locales_of<I>(input: I) -> Self::Iter
where
I: IntoIterator<Item = Locale> {
input.into_iter().filter(|loc| AVAILABLE_LOCALES.contains(loc))
}
}
but that doesn't work because I need GAT or a concrete type in the implementation.
What concrete type should I use or is there another way to handle such scenario?