Converting BoxStream to BoxFuture
I have a function that returns BoxStream<(), io::Error>
and wants to convert this stream to Future
(or BoxFuture
), but I am having some problems with the compiler:
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 to get around this?
+3
source to share
1 answer
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 check the difference with
fn main() { let a = futures::future::IntoFuture::into_future(foo()); let a = futures::Stream::into_future(foo()); }
+3
source to share