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>
impl<'a> Debug for StringReader<'a>
Source§impl<'a> Reader for StringReader<'a>
impl<'a> Reader for StringReader<'a>
Source§type Error = Infallible
type Error = Infallible
The error returned by this reader.
Source§fn read_byte(&mut self) -> Result<Option<u8>, Self::Error>
fn read_byte(&mut self) -> Result<Option<u8>, Self::Error>
Return a new byte from the input stream. 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more