aboutsummaryrefslogtreecommitdiffstats
path: root/components/selectors/tree.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/selectors/tree.rs')
-rw-r--r--components/selectors/tree.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/components/selectors/tree.rs b/components/selectors/tree.rs
index 23238237b2f..958311ad0d8 100644
--- a/components/selectors/tree.rs
+++ b/components/selectors/tree.rs
@@ -8,11 +8,27 @@
use attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity};
use matching::{ElementSelectorFlags, LocalMatchingContext, MatchingContext, RelevantLinkStatus};
use parser::SelectorImpl;
+use servo_arc::NonZeroPtrMut;
use std::fmt::Debug;
-pub trait Element: Sized + Debug {
+/// Opaque representation of an Element, for identity comparisons. We use
+/// NonZeroPtrMut to get the NonZero optimization.
+#[derive(Clone, Debug, Eq, Hash, PartialEq)]
+pub struct OpaqueElement(pub NonZeroPtrMut<()>);
+
+impl OpaqueElement {
+ /// Creates a new OpaqueElement from an arbitrarily-typed pointer.
+ pub fn new<T>(ptr: *const T) -> Self {
+ OpaqueElement(NonZeroPtrMut::new(ptr as *const () as *mut ()))
+ }
+}
+
+pub trait Element: Sized + Clone + Debug {
type Impl: SelectorImpl;
+ /// Converts self into an opaque representation.
+ fn opaque(&self) -> OpaqueElement;
+
fn parent_element(&self) -> Option<Self>;
/// The parent of a given pseudo-element, after matching a pseudo-element