Hi, this snippet fails with the error:
use futures; // 0.3.4
use futures::stream::{StreamExt};
async fn test() {
let data = std::sync::Arc::new(vec![1i32,2,3,4]);
tokio::spawn(async move {
futures::stream::iter(data.iter())
.map(|_| async move {
12i32
})
.buffer_unordered(32usize)
.collect::<Vec<_>>()
.await;
});
}
here is the error:
error: implementation of `std::iter::Iterator` is not general enough
--> src/lib.rs:7:5
|
7 | tokio::spawn(async move {
| ^^^^^^^^^^^^ implementation of `std::iter::Iterator` is not general enough
|
= note: `std::iter::Iterator` would have to be implemented for the type `std::slice::Iter<'0, i32>`, for any lifetime `'0`...
= note: ...but `std::iter::Iterator` is actually implemented for the type `std::slice::Iter<'1, i32>`, for some specific lifetime `'1`
Please anyone explain me whats happening there, I found workaround for that using copied
:
use futures; // 0.3.4
use futures::stream::{StreamExt};
async fn test() {
let data = std::sync::Arc::new(vec![1i32,2,3,4]);
tokio::spawn(async move {
futures::stream::iter(data.iter().copied())
.map(|_| async move {
12i32
})
.buffer_unordered(32usize)
.collect::<Vec<_>>()
.await;
});
}
But I am not quite understand why this error happen?