I'm trying to define a generic type that holds a Stream, and add a convenience method for constructing this type from something iterable that will use futures::stream::iter_ok() to convert the iterable object into a stream. Here's what I have
struct StreamHolder<S: Stream> {
stream: S,
}
impl<S> StreamHolder<S>
where
S: Stream,
{
pub fn new(stream: S) -> Self {
Self { stream }
}
}
impl<I: IntoIterator> StreamHolder<IterOk<I::IntoIter, ()>>
where
I: IntoIterator,
{
pub fn from_iter(iter: I) -> Self {
StreamHolder::new(futures01::stream::iter_ok::<_, ()>(iter))
}
}
The goal is to be able to say something like:
let v = vec!["a", "b"];
let stream_holder = StreamHolder::from_iter(v);
But when I try to compile this I get:
error[E0207]: the type parameter I
is not constrained by the impl trait, self type, or predicates
--> src/sources/socket/mod.rs:358:10
|
358 | impl<I: IntoIterator> StreamHolder<IterOk<I::IntoIter, ()>>
| ^ unconstrained type parameter