Tokio v0.2.3
carllerche
released this
06 Dec 17:57
·
2375 commits
to master
since this release
Mostly a bug fix, doc improvement, and polish release. The biggest new addition are the new helpers to read and write integers. They are on AsyncReadExt
and AsyncWriteExt
and can make protocol encoding / decoding easier. For example, working with length delimited payloads might look like:
use tokio::io::{self, AsyncReadExt, AsyncWriteExt, BufStream};
use tokio::net::TcpStream;
async fn read_frame(src: &mut BufStream<TcpStream>) -> io::Result<Vec<u8>> {
let len = src.read_u32().await?;
let mut frame = vec![0; len as usize];
src.read_exact(&mut frame).await?;
Ok(frame)
}
async fn write_frame(dst: &mut BufStream<TcpStream>, frame: &[u8]) -> io::Result<()> {
dst.write_u32(frame.len() as u32).await?;
dst.write_all(frame).await?;
dst.flush().await?;
Ok(())
}
Added
- read / write integers using
AsyncReadExt
andAsyncWriteExt
(#1863). read_buf
/write_buf
for reading / writingBuf
/BufMut
(#1881).TcpStream::poll_peek
- pollable API for performing TCP peek (#1864).sync::oneshot::error::TryRecvError
provides variants to detect the error
kind (#1874).LocalSet::block_on
accepts!'static
task (#1882).task::JoinError
is nowSync
(#1888).- impl conversions between
tokio::time::Instant
and
std::time::Instant
(#1904).