Crate buf_redux [] [src]

Drop-in replacements for buffered I/O types in std::io.

These replacements retain the method names/signatures and implemented traits of their stdlib counterparts, making replacement as simple as swapping the import of the type:


- use std::io::BufReader;
+ use buf_redux::BufReader;


- use std::io::BufWriter;
+ use buf_redux::BufWriter;


- use std::io::LineWriter;
+ use buf_redux::LineWriter;

More Direct Control

All replacement types provide methods to:

  • Increase the capacity of the buffer
  • Get the number of available bytes as well as the total capacity of the buffer
  • Consume the wrapper without losing data

BufReader provides methods to:

  • Access the buffer through an &-reference without performing I/O
  • Force unconditional reads into the buffer
  • Get a Read adapter which empties the buffer and then pulls from the inner reader directly
  • Shuffle bytes down to the beginning of the buffer to make room for more reading
  • Get inner reader and trimmed buffer with the remaining data

BufWriter and LineWriter provides methods to:

  • Flush the buffer and unwrap the inner writer unconditionally.
  • Get the inner writer and trimmed buffer with the unflushed data.

More Sensible and Customizable Buffering Behavior

  • Tune the behavior of the buffer to your specific use-case using the types in the strategy module:
    • BufReader performs reads as dictated by the ReadStrategy trait.
    • BufReader moves bytes down to the beginning of the buffer, to make more room at the end, when deemed appropriate by the MoveStrategy trait.
    • BufWriter flushes bytes to the inner writer when full, or when deemed appropriate by the FlushStrategy trait.
  • Buffer uses exact allocation instead of leaving it up to Vec, which allocates sizes in powers of two.
    • Vec's behavior is more efficient for frequent growth, but much too greedy for infrequent growth and custom capacities.



Types which can be used to tune the behavior of BufReader.



A drop-in replacement for std::io::BufReader with more functionality.


A drop-in replacement for std::io::BufWriter with more functionality.


A deque-like datastructure for managing bytes.


The error type for BufWriter::into_inner(), contains the BufWriter as well as the error that occurred.


A drop-in replacement for std::io::LineWriter with more functionality.


A Read adapter for a consumed BufReader which will empty bytes from the buffer before reading from inner directly. Frees the buffer when it has been emptied.



A trait which Buffer can use to determine whether or not it is safe to elide zeroing of its buffer.



Copy data between a BufRead and a Write without an intermediate buffer.