impl AsyncRead for SmolSocket {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut tokio::io::ReadBuf<'_>,
) -> Poll<std::io::Result<()>> {
//closure because Poll does not implement clone
let packet_missing = ||{Poll::Ready(Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "tcp packet missing")))};
let tcp_packet = match &packet.tcp {
Some(packet) => packet,
None => return packet_missing()
};
Since the return type of poll_read
is not a Result
, I cannot do
let tcp_packet = &packet.tcp.unwrap_or(packet_missing)?
to return the value. I have to do this match
everytime, and I need to do it more than once, so it's ugly to leave it like this. I think the ready!
macro would solve this but it is experimental ready in std::task - Rust
Is there a more elegant solution?