rust-scraper/scraper

Feature request: implement `DoubleEndedIterator` for `Select`

arctic-penguin opened this issue · 2 comments

This should work, since Nodes already implements DEE.

impl<'a, 'b> DoubleEndedIterator for Select<'a, 'b> {
    fn next_back(&mut self) -> Option<Self::Item> {
        for node in self.inner.by_ref().rev() {
            if let Some(element) = ElementRef::wrap(node) {
                if element.parent().is_some() && self.selector.matches(&element) {
                    return Some(element);
                }
            }
        }
        None
    }
}

A patch with some test cases would be welcome.

@arctic-penguin your code LGTM. I do not have much time rn but I would gladly review a PR (with some test cases, as @teymour-aldridge said).
TIA