#io-stream #async-io #read-write #buffered #async-read #async-write #tokio

bufstream

Buffered I/O for streams where each read/write half is separately buffered

5 releases

Uses old Rust 2015

0.1.4 Sep 27, 2018
0.1.3 Apr 26, 2017
0.1.2 Apr 29, 2016
0.1.1 May 13, 2015
0.1.0 May 5, 2015

#929 in Asynchronous

Download history 18380/week @ 2024-07-21 20026/week @ 2024-07-28 15562/week @ 2024-08-04 16980/week @ 2024-08-11 16422/week @ 2024-08-18 16916/week @ 2024-08-25 18297/week @ 2024-09-01 17568/week @ 2024-09-08 16733/week @ 2024-09-15 17616/week @ 2024-09-22 19360/week @ 2024-09-29 19243/week @ 2024-10-06 25123/week @ 2024-10-13 23364/week @ 2024-10-20 25428/week @ 2024-10-27 19449/week @ 2024-11-03

94,419 downloads per month
Used in fewer than 60 crates

MIT/Apache

11KB
138 lines

bufstream

Buffered I/O streams for reading/writing

Build Status

Documentation

Usage

[dependencies]
bufstream = "0.1"

Tokio

There is support for tokio's AsyncRead + AsyncWrite traits through the tokio feature. When using this crate with asynchronous IO, make sure to properly flush the stream before dropping it since IO during drop may cause panics. For the same reason you should stay away from BufStream::into_inner.


lib.rs:

A crate for separately buffered streams.

This crate provides a BufStream type which provides buffering of both the reading and writing halves of a Read + Write type. Each half is completely independently buffered of the other, which may not always be desired. For example BufStream<File> may have surprising semantics.

Usage

[dependencies]
bufstream = "0.1"
use std::io::prelude::*;
use std::net::TcpStream;
use bufstream::BufStream;


let stream = TcpStream::connect("localhost:4000").unwrap();
let mut buf = BufStream::new(stream);
buf.read(&mut [0; 1024]).unwrap();
buf.write(&[0; 1024]).unwrap();

Async I/O

This crate optionally can support async I/O streams with the Tokio stack via the tokio feature of this crate:

bufstream = { version = "0.2", features = ["tokio"] }

All methods are internally capable of working with streams that may return ErrorKind::WouldBlock when they're not ready to perform the particular operation.

Note that care needs to be taken when using these objects, however. The Tokio runtime, in particular, requires that data is fully flushed before dropping streams. For compatibility with blocking streams all streams are flushed/written when they are dropped, and this is not always a suitable time to perform I/O. If I/O streams are flushed before drop, however, then these operations will be a noop.

Dependencies

~105KB