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, and storing the read data:

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() {
        Ok(s) => {
            if s.len() == 0 { break; } // EOF
            text.push_str(s.as_str()) // Append read chunk to text
        }
        Err(e) => panic!(e), // io::Error or Utf8Error
    }
}
assert_eq!("💖", text.as_str());

see BufRead’s documentation for more.

Traits

BufRead

A trait implemented for all types implementing io::BufRead, providing functions to read utf-8 text streams without waiting for newline delimiters.