Skip to content

Tokio v0.2.3

Compare
Choose a tag to compare
@carllerche carllerche released this 06 Dec 17:57
· 2375 commits to master since this release
98c9a77

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 and AsyncWriteExt (#1863).
  • read_buf / write_buf for reading / writing Buf / 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 now Sync (#1888).
  • impl conversions between tokio::time::Instant and
    std::time::Instant (#1904).

Fixes