The tokio::select! macro uses a custom DSL, which means it can't be formatted by rustfmt, which is a huge problem!
tokio::select! {
res = reader.read(&mut buf), if can_read => {
let n = res?;
if n == 0 { return Ok(()); }
writer.write_all(&buf[..n]).await?;
}
_ = shutdown.recv() => {
return Ok(());
}
}
This macro, tokio_select from the better_tokio_select crate I just released, can do everything that tokio::select! can, but it can also be formatted by rustfmt, because the syntax is 100% valid Rust:
tokio_select!(match .. {
.. if let Ok(n) = reader.read(&mut buf) && can_read => {
let n = res?;
if n == 0 { return Ok(()); }
writer.write_all(&buf[..n]).await?;
}
.. if let _ = shutdown.recv() => {
return Ok(())
}
})