Struct StringReader

Source
pub struct StringReader<'a> { /* private fields */ }
Expand description

A helper struct to seek forwards and backwards in strings. Used by the tokenizer to read HTML from strings.

Example:

use std::fmt::Write;
use html5gum::{Tokenizer, Token};

let html = "<title   >hello world</title>";
let mut new_html = String::new();

for Ok(token) in Tokenizer::new(html) {
    match token {
        Token::StartTag(tag) => {
            write!(new_html, "<{}>", String::from_utf8_lossy(&tag.name)).unwrap();
        }
        Token::String(hello_world) => {
            write!(new_html, "{}", String::from_utf8_lossy(&hello_world)).unwrap();
        }
        Token::EndTag(tag) => {
            write!(new_html, "</{}>", String::from_utf8_lossy(&tag.name)).unwrap();
        }
        _ => panic!("unexpected input"),
    }
}

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

Trait Implementations§

Source§

impl<'a> Debug for StringReader<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Reader for StringReader<'a>

Source§

type Error = Infallible

The error returned by this reader.
Source§

fn read_byte(&mut self) -> Result<Option<u8>, Self::Error>

Return a new byte from the input stream. Read more
Source§

fn read_until<'b>( &'b mut self, needle: &[u8], _: &'b mut [u8; 4], ) -> Result<Option<&'b [u8]>, Self::Error>

Read an arbitrary amount of characters up until and including the next character that matches an array entry in needle. Read more
Source§

fn try_read_string( &mut self, s1: &[u8], case_sensitive: bool, ) -> Result<bool, Self::Error>

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

Auto Trait Implementations§

§

impl<'a> Freeze for StringReader<'a>

§

impl<'a> RefUnwindSafe for StringReader<'a>

§

impl<'a> Send for StringReader<'a>

§

impl<'a> Sync for StringReader<'a>

§

impl<'a> Unpin for StringReader<'a>

§

impl<'a> UnwindSafe for StringReader<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'a, R> Readable<'a> for R
where R: 'a + Reader,

Source§

type Reader = R

The reader type to which this type should be converted.
Source§

fn to_reader(self) -> <R as Readable<'a>>::Reader

Convert self to some sort of reader.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.