I have a function which returns a BoxStream<(), io::Error> and would like to convert this stream into a Future (or BoxFuture) but I'm having some compiler issues:
extern crate futures;
use futures::stream::BoxStream;
use std::io;
pub fn foo() -> BoxStream<(), io::Error> {
unimplemented!()
}
fn main() {
let a = foo().into_future();
}
And the error message:
error[E0277]: the trait bound `futures::Stream<Error=std::io::Error, Item=()> + std::marker::Send + 'static: std::marker::Sized` is not satisfied
--> src/main.rs:23:19
|
23 | let a = foo().into_future();
| ^^^^^^^^^^^ the trait `std::marker::Sized` is not implemented for `futures::Stream<Error=std::io::Error, Item=()> + std::marker::Send + 'static`
|
= note: `futures::Stream<Error=std::io::Error, Item=()> + std::marker::Send + 'static` does not have a constant size known at compile-time
Is there a way around this?
You are calling futures::future::IntoFuture::into_future, not futures::stream::Stream::into_future. You need to import the trait:
extern crate futures;
use futures::Stream; // This
use futures::stream::BoxStream;
use std::io;
pub fn foo() -> BoxStream<(), io::Error> {
unimplemented!()
}
fn main() {
let a = foo().into_future();
}
You can validate the difference with
fn main() {
let a = futures::future::IntoFuture::into_future(foo());
let a = futures::Stream::into_future(foo());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With