pub struct HtmlParser { /* private fields */ }Expand description
A configured HTML parser instance.
Create via HtmlParser::builder() for custom configuration, or use the
convenience methods HtmlParser::parse() and HtmlParser::parse_bytes()
for defaults.
§Example
use fast_html_parser::HtmlParser;
// One-shot convenience
let doc = HtmlParser::parse("<p>Hello</p>").unwrap();
// Builder pattern
let parser = HtmlParser::builder()
.max_input_size(1024 * 1024)
.build();
let doc = parser.parse_str("<p>World</p>").unwrap();Implementations§
Source§impl HtmlParser
impl HtmlParser
Sourcepub fn builder() -> ParserBuilder
pub fn builder() -> ParserBuilder
Create a new ParserBuilder.
Sourcepub fn parse(input: &str) -> Result<Document, HtmlError>
pub fn parse(input: &str) -> Result<Document, HtmlError>
Parse an HTML string with default settings.
This is a convenience wrapper around fhp_tree::parse().
§Errors
Returns HtmlError::InputTooLarge if the input exceeds 256 MiB.
§Example
use fast_html_parser::HtmlParser;
let doc = HtmlParser::parse("<div><p>Hello</p></div>").unwrap();
assert_eq!(doc.root().text_content(), "Hello");Sourcepub fn parse_owned(input: String) -> Result<Document, HtmlError>
pub fn parse_owned(input: String) -> Result<Document, HtmlError>
Parse an owned String with default settings, transferring the allocation.
Avoids a memcpy of the source bytes when the caller already owns the input (e.g., from an HTTP response body).
§Errors
Returns HtmlError::InputTooLarge if the input exceeds 256 MiB.
§Example
use fast_html_parser::HtmlParser;
let html = String::from("<div><p>Hello</p></div>");
let doc = HtmlParser::parse_owned(html).unwrap();
assert_eq!(doc.root().text_content(), "Hello");Sourcepub fn parse_bytes(input: &[u8]) -> Result<Document, HtmlError>
pub fn parse_bytes(input: &[u8]) -> Result<Document, HtmlError>
Parse raw bytes with default settings, auto-detecting encoding.
§Errors
Returns HtmlError::InputTooLarge or HtmlError::Encoding on
failure.
§Example
use fast_html_parser::HtmlParser;
let doc = HtmlParser::parse_bytes(b"<p>Hello</p>").unwrap();
assert_eq!(doc.root().text_content(), "Hello");Sourcepub fn parse_str(&self, input: &str) -> Result<Document, HtmlError>
pub fn parse_str(&self, input: &str) -> Result<Document, HtmlError>
Parse an HTML string with the current configuration.
§Errors
Returns HtmlError::InputTooLarge if the input exceeds the
configured limit.
Sourcepub fn parse_str_owned(&self, input: String) -> Result<Document, HtmlError>
pub fn parse_str_owned(&self, input: String) -> Result<Document, HtmlError>
Parse an owned String with the current configuration.
Avoids a memcpy of the source bytes when the caller already owns the input (e.g., from an HTTP response body).
§Errors
Returns HtmlError::InputTooLarge if the input exceeds the
configured limit.
Sourcepub fn parse_raw(&self, input: &[u8]) -> Result<Document, HtmlError>
pub fn parse_raw(&self, input: &[u8]) -> Result<Document, HtmlError>
Parse raw bytes with the current configuration, auto-detecting encoding.
§Errors
Returns HtmlError::InputTooLarge or HtmlError::Encoding on
failure.