According to the doc of .try_iter() method of the Receiver
end of a Rust std::mpsc::channel
, I understand that this iterator either yield "None":
- when there is no data in the channel
- or when the other end of the channel has hung up.
In my case, I would like to peek
into the channel, without blocking, so as to determinate whether:
- there is data (but without consuming it), or
- there is no data, or
- the channel has hung up.
The problem is that if I..
match my_receiver.try_iter().peekable().peek() {
Some(data) => {/* there is data */}
None => {/* there is no data, but there may be later.. or maybe not, because the channel has maybe hung up, I can't tell! */}
}
.. there are only two cases I can discriminate.
How can I peek into the receiver
end of a channel and discriminate between those three possible outcomes without blocking or consuming the data when there is some?
match
: your top-level one can match directly onSome (Ok (data))
andSome (Err (_))
(playground). – Hanrahan