Skip to main content

HtmlParser

Struct HtmlParser 

Source
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

Source

pub fn builder() -> ParserBuilder

Create a new ParserBuilder.

Source

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");
Source

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");
Source

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");
Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

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<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.