-
Notifications
You must be signed in to change notification settings - Fork 656
Description
I noticed that recently send_all signature was updated to require TryStream bound on passed stream (#1946).
I wonder if there is a reason for this restriction?
Consider the following code that I have:
type TestData = HashMap<String, usize>;
let sink: Sink<TestData> = ...;
let msg1 = HashMap::new();
let msg2 = HashMap::new();
let mut msgs = futures::stream::iter(vec![msg1, msg2]);
sender.send_all(&mut msgs).await?;
This fails with following error:
error[E0271]: type mismatch resolving `<futures_util::stream::iter::Iter<std::vec::IntoIter<std::collections::HashMap<std::string::String, usize>>> as futures_core::stream::Stream>::Item == std::result::Result<_, _>`
--> examples/basic.rs:55:12
|
55 | sender.send_all(&mut msgs).await?;
| ^^^^^^^^ expected struct `std::collections::HashMap`, found enum `std::result::Result`
|
= note: expected type `std::collections::HashMap<std::string::String, usize>`
found enum `std::result::Result<_, _>`
= note: required because of the requirements on the impl of `futures_core::stream::TryStream` for `futures_util::stream::iter::Iter<std::vec::IntoIter<std::collections::HashMap<std::string::String, usize>>>`
Took me some time to decrypt that this happens because stream::iter::Iter does not implement TryStream and gets automatic implementation only if stream's item is std::result::Result. So, in simple code above I have to wrap each message into Ok like futures::stream::iter(vec![Ok(msg1), Ok(msg2)])
which looks weird.
Shouldn't it be possible to send streams that produce items for sure and can't fail? Unless I am missing something obvious that makes it undesirable/not possible, I think sinking collection of values is rather often use case.