Crate bufstream [] [src]

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.


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); [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.



Wraps a Stream and buffers input and output to and from it.


An error returned by into_inner which combines an error that happened while writing out the buffer, and the buffered writer object which may be used to recover from the condition.