1#![doc = include_str!("../README.md")]
2#![deny(missing_docs)]
3#![cfg_attr(not(feature = "std"), no_std)]
4#![cfg_attr(feature = "portable-simd", feature(portable_simd))]
5
6mod bytes;
7pub mod errors;
9pub mod inline;
11mod parser;
12pub mod queryselector;
14mod stream;
15#[cfg(all(test, feature = "std"))]
16mod tests;
17mod util;
18mod vdom;
19
20#[doc(hidden)]
21#[cfg(feature = "__INTERNALS_DO_NOT_USE")]
22pub mod simd;
23#[cfg(not(feature = "__INTERNALS_DO_NOT_USE"))]
24mod simd;
25
26pub use bytes::Bytes;
27pub use errors::ParseError;
28pub use parser::*;
29use queryselector::Selector;
30pub use vdom::VDom;
31#[cfg(feature = "std")]
32pub use vdom::VDomGuard;
33
34#[cfg(feature = "std")]
35const STD_INLINE_CLASS_HANDLES: usize = 32;
36#[cfg(feature = "std")]
37const STD_INLINE_IDS: usize = 16;
38#[cfg(feature = "std")]
39const STD_INLINE_CLASSES: usize = 16;
40
41#[cfg(feature = "std")]
60pub fn parse(
61 input: &str,
62 options: ParserOptions,
63) -> Result<
64 VDom<'_, STD_INLINE_CLASS_HANDLES, 0, 0, STD_INLINE_IDS, STD_INLINE_CLASSES, 0>,
65 ParseError,
66> {
67 let mut parser =
68 Parser::<STD_INLINE_CLASS_HANDLES, 0, 0, STD_INLINE_IDS, STD_INLINE_CLASSES, 0>::new(
69 input, options,
70 );
71 parser.parse()?;
72 Ok(VDom::from(parser))
73}
74
75#[cfg(not(feature = "std"))]
80pub fn parse<
81 const MAX_NODES: usize,
82 const MAX_STACK: usize,
83 const MAX_ROOTS: usize,
84 const MAX_IDS: usize,
85 const MAX_CLASSES: usize,
86 const MAX_SELECTOR_NODES: usize,
87>(
88 input: &str,
89 options: ParserOptions,
90) -> Result<
91 VDom<'_, MAX_NODES, MAX_STACK, MAX_ROOTS, MAX_IDS, MAX_CLASSES, MAX_SELECTOR_NODES>,
92 ParseError,
93> {
94 let mut parser = Parser::new(input, options);
95 parser.parse()?;
96 Ok(VDom::from(parser))
97}
98
99#[cfg(feature = "std")]
115pub fn parse_query_selector(input: &str) -> Option<Selector<'_>> {
116 let selector = queryselector::Parser::new(input.as_bytes()).selector()?;
117 Some(selector)
118}
119
120#[cfg(not(feature = "std"))]
122pub fn parse_query_selector<const MAX_SELECTOR_NODES: usize>(
123 input: &str,
124) -> Result<Selector<'_, MAX_SELECTOR_NODES>, ParseError> {
125 queryselector::Parser::new(input.as_bytes()).selector::<MAX_SELECTOR_NODES>()
126}
127
128#[cfg(feature = "std")]
139pub unsafe fn parse_owned(input: String, options: ParserOptions) -> Result<VDomGuard, ParseError> {
140 VDomGuard::parse(input, options)
141}