lewp_css/domain/selectors/
matches.rs

1// This file is part of css. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2017 The developers of css. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT.
3
4use selectors::{
5    context::{MatchingMode, QuirksMode},
6    matching::{matches_selector, MatchingContext},
7    parser::{AncestorHashes, Selector},
8    Element,
9    NthIndexCache,
10};
11
12/// Returns whether the given element matches this selector.
13#[inline]
14pub fn matches<E: Element>(selector: &Selector<E::Impl>, element: &E) -> bool {
15    const offset: usize = 0;
16    const hashes: Option<&AncestorHashes> = None;
17    const nth_index_cache: Option<&mut NthIndexCache> = None;
18    let mut context = MatchingContext::new(
19        MatchingMode::Normal,
20        None,
21        nth_index_cache,
22        QuirksMode::NoQuirks,
23    );
24    matches_selector(
25        selector,
26        offset,
27        hashes,
28        element,
29        &mut context,
30        &mut |_, _| {},
31    )
32}