MCPcopy Create free account
hub / github.com/Stranger6667/css-inline / select

Function select

css-inline/src/html/iter.rs:31–59  ·  view source on GitHub ↗
(
    document: &'a Document,
    selectors: &'b str,
    caches: &'c mut SelectorCaches,
)

Source from the content-addressed store, hash-verified

29/// Compile selectors from a string and create an element iterator that yields elements matching these selectors.
30#[inline]
31pub(crate) fn select<'a, 'b, 'c>(
32 document: &'a Document,
33 selectors: &'b str,
34 caches: &'c mut SelectorCaches,
35) -> Result<Select<'a, 'c>, ParseError<'b>> {
36 Selectors::compile(selectors).map(|selectors| {
37 // Only use indexes if they were built during parsing
38 let source = if document.has_indexes() {
39 match selectors.anchor() {
40 SelectorAnchor::Id(id) => ElementSource::Single(document.get_by_id(id.as_inner())),
41 SelectorAnchor::Class(class) => {
42 ElementSource::Slice(document.get_by_class(class.as_inner()).iter())
43 }
44 SelectorAnchor::Tag(tag) => {
45 ElementSource::Slice(document.get_by_tag(tag.as_inner()).iter())
46 }
47 SelectorAnchor::None => ElementSource::Slice(document.elements.iter()),
48 }
49 } else {
50 ElementSource::Slice(document.elements.iter())
51 };
52 Select {
53 document,
54 caches,
55 source,
56 selectors,
57 }
58 })
59}
60
61/// An element iterator adaptor that yields elements matching given selectors.
62pub(crate) struct Select<'a, 'c> {

Callers 1

selectMethod · 0.85

Calls 7

has_indexesMethod · 0.80
anchorMethod · 0.80
get_by_idMethod · 0.80
as_innerMethod · 0.80
iterMethod · 0.80
get_by_classMethod · 0.80
get_by_tagMethod · 0.80

Tested by

no test coverage detected