Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Some docstrings for the matcher module #11

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/matchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ use std::iter;
/// An iterator over matcher selection results.
type Iter<'a> = Box<dyn Iterator<Item = &'a Value> + 'a>;

// Matcher maps a node to a list of nodes. If the input node is not matched by the matcher or
// the matcher does not select any subnodes of the input node, then the result is empty.
/// Matcher maps a node to a list of nodes. If the input node is not matched by the matcher or
/// the matcher does not select any subnodes of the input node, then the result is empty.
pub trait Matcher {
fn select<'a>(&'a self, node: &'a Value) -> Iter<'a>;
}

/// Selects exactly one item, namely the node
/// of the subtree the selector is applied to.
///
/// (which may or may be not the actual root of the document).
pub struct RootSelector {}

impl Matcher for RootSelector {
Expand All @@ -24,6 +28,7 @@ impl Matcher for RootSelector {
}
}

/// Selects all children of a node.
pub struct WildcardedChild {}

impl Matcher for WildcardedChild {
Expand All @@ -36,6 +41,7 @@ impl Matcher for WildcardedChild {
}
}

/// Selects a named child.
pub struct Child {
name: String,
}
Expand All @@ -52,6 +58,8 @@ impl Matcher for Child {
}
}

/// Applies a sequence of selectors on the same node and returns
/// a concatenation of the results.
pub struct Union {
elements: Vec<Box<dyn Matcher>>,
}
Expand Down