1mod matcher;
4pub mod selector;
5mod types;
6#[cfg(feature = "wasm")]
7mod index;
8
9use selector::parse_selector as parse_selector_impl;
10
11pub use types::{AttrName, TagName};
12
13pub use matcher::{filter_by_selector, filter_by_selector_indexed, matches_compound, Matchable};
14pub use selector::{
15 AttrOp, AttrPredicate, Combinator, CompoundSelector, Predicate, PredicateOp, PredicateValue,
16 SelectorAst,
17};
18
19use serde_json::Value as JsonValue;
20use std::borrow::Cow;
21
22#[must_use = "parsing a selector is useless without inspecting the result"]
24pub fn parse_selector(selector: &str) -> Result<SelectorAst, String> {
25 parse_selector_impl(selector)
26}
27
28pub(crate) fn json_value_to_string(v: &JsonValue) -> Cow<'_, str> {
31 match v {
32 JsonValue::String(s) => Cow::Borrowed(s.as_str()),
33 JsonValue::Bool(b) => Cow::Owned(b.to_string()),
34 JsonValue::Number(n) => Cow::Owned(n.to_string()),
35 JsonValue::Null => Cow::Borrowed(""),
36 other => Cow::Owned(other.to_string()),
37 }
38}
39