Skip to content

Commit

Permalink
Document selectors::Visit
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jan 12, 2018
1 parent c14b766 commit 1a6010f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
10 changes: 1 addition & 9 deletions components/selectors/parser.rs
Expand Up @@ -19,7 +19,7 @@ use std::borrow::{Borrow, Cow};
use std::fmt::{self, Display, Debug, Write};
use std::iter::Rev;
use std::slice;
use visitor::SelectorVisitor;
pub use visitor::{Visit, SelectorVisitor};

/// A trait that represents a pseudo-element.
pub trait PseudoElement : Sized + ToCss {
Expand Down Expand Up @@ -326,14 +326,6 @@ impl AncestorHashes {
}
}

pub trait Visit {
type Impl: SelectorImpl;

fn visit<V>(&self, visitor: &mut V) -> bool
where
V: SelectorVisitor<Impl = Self::Impl>;
}

impl<Impl: SelectorImpl> Visit for Selector<Impl> {
type Impl = Impl;

Expand Down
28 changes: 28 additions & 0 deletions components/selectors/visitor.rs
Expand Up @@ -44,3 +44,31 @@ pub trait SelectorVisitor {
true
}
}

/// Enables traversing selector components stored in various types
pub trait Visit {
/// The type parameter of selector component types.
type Impl: SelectorImpl;

/// Traverse selector components inside `self`.
///
/// Implementations of this method should call `SelectorVisitor` methods
/// or other impls of `Visit` as appropriate based on the fields of `Self`.
///
/// A return value of `false` indicates terminating the traversal.
/// It should be propagated with an early return.
/// On the contrary, `true` indicates that all fields of `self` have been traversed:
///
/// ```rust,ignore
/// if !visitor.visit_simple_selector(&self.some_simple_selector) {
/// return false;
/// }
/// if !self.some_component.visit(visitor) {
/// return false;
/// }
/// true
/// ```
fn visit<V>(&self, visitor: &mut V) -> bool
where
V: SelectorVisitor<Impl = Self::Impl>;
}

0 comments on commit 1a6010f

Please sign in to comment.