Crate utf8_bufread[−][src]
This crate provides a trait, BufRead
, providing functions to read utf-8 text streams
using an io::BufRead
without waiting for newline delimiters.
Quick Start
The simplest way to read a whole file with a BufRead
type is to repeatedly calling its
read_utf8
method:
use utf8_bufread::BufRead; use std::io::BufReader; // Reader may be any type implementing io::BufRead // We'll just use a BufReader wrapping a slice for this example let mut reader = BufReader::<&[u8]>::new("💖".as_ref()); // The string we'll use to store the text of the read file let mut text = String::new(); loop { // Loop until EOF match reader.read_utf8(&mut text) { Ok(0) => break, // EOF Ok(_) => continue, Err(e) => panic!(e), // io::Error or Utf8Error } } assert_eq!("💖", text.as_str());
Note that this example does exactly what this crate tries to avoid: storing the whole file in memory.
see BufRead
’s documentation for more.
Traits
BufRead | A trait implemented for all types implementing |