github tokio-rs/tokio tokio-0.2.3
Tokio v0.2.3

latest releases: tokio-util-0.7.11, tokio-1.37.0, tokio-test-0.4.4...
4 years ago

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

Don't miss a new tokio release

NewReleases is sending notifications on new releases.