(
document: &'a Document,
selectors: &'b str,
caches: &'c mut SelectorCaches,
)
| 29 | /// Compile selectors from a string and create an element iterator that yields elements matching these selectors. |
| 30 | #[inline] |
| 31 | pub(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. |
| 62 | pub(crate) struct Select<'a, 'c> { |
no test coverage detected