Struct html5tokenizer::BufReadReader[][src]

pub struct BufReadReader<R: BufRead> { /* fields omitted */ }
Expand description

A BufReadReader can be used to construct a tokenizer from any type that implements BufRead.

Example:

use std::io::BufReader;
use std::fmt::Write;
use html5tokenizer::{Token, BufReadReader, Tokenizer};

let tokenizer = Tokenizer::new(BufReader::new("<title>hello world</title>".as_bytes()));
// or alternatively:
// tokenizer = Tokenizer::new(BufReadReader::new(BufReader::new("...".as_bytes())));

let mut new_html = String::new();

for token in tokenizer {
    let token = token.unwrap();

    match token {
        Token::StartTag(tag) => {
            write!(new_html, "<{}>", tag.name).unwrap();
        }
        Token::String(hello_world) => {
            write!(new_html, "{}", hello_world).unwrap();
        }
        Token::EndTag(tag) => {
            write!(new_html, "</{}>", tag.name).unwrap();
        }
        _ => panic!("unexpected input"),
    }
     
}

assert_eq!(new_html, "<title>hello world</title>");

Implementations

Construct a new BufReadReader from any type that implements BufRead.

Trait Implementations

The error returned by this reader.

Return a new character from the input stream. Read more

Attempt to read an entire string at once, either case-insensitively or not. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.