summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-04-04 23:15:03 +0200
committerLaurenz <laurmaedje@gmail.com>2023-04-04 23:15:03 +0200
commit23715e813e1888c8c317ec2f9649d0f1ad46bd8c (patch)
tree19e023514700cb9ec69285cafe658964aec4ee60 /src/model
parentf347ed4314e32383dc09ff234180e8ea6fef7b8b (diff)
Refactor and document figures
Diffstat (limited to 'src/model')
-rw-r--r--src/model/content.rs29
1 files changed, 8 insertions, 21 deletions
diff --git a/src/model/content.rs b/src/model/content.rs
index db867715..da3b8b75 100644
--- a/src/model/content.rs
+++ b/src/model/content.rs
@@ -354,28 +354,11 @@ impl Content {
self.attrs.push(Attr::Location(location));
}
- /// Gives an iterator over the children of this content
- pub fn children(&self) -> impl Iterator<Item = &Content> {
- self.attrs.iter().filter_map(Attr::child)
- }
-
- /// Gives an iterator over the children of this content that are contained
- /// within the arguments of the content.
- pub fn children_in_args(&self) -> impl Iterator<Item = &Content> {
- self.attrs
- .iter()
- .filter_map(Attr::value)
- .filter_map(|value| match value {
- Value::Content(content) => Some(content),
- _ => None,
- })
- }
-
/// Queries the content tree for all elements that match the given selector.
///
/// # Show rules
/// Elements produced in `show` rules will not be included in the results.
- pub fn query(&self, selector: Selector) -> Vec<Content> {
+ pub fn query(&self, selector: Selector) -> Vec<&Content> {
let mut results = Vec::new();
self.query_into(&selector, &mut results);
results
@@ -383,9 +366,9 @@ impl Content {
/// Queries the content tree for all elements that match the given selector
/// and stores the results inside of the `results` vec.
- fn query_into(&self, selector: &Selector, results: &mut Vec<Content>) {
+ fn query_into<'a>(&'a self, selector: &Selector, results: &mut Vec<&'a Content>) {
if selector.matches(self) {
- results.push(self.clone());
+ results.push(self);
}
for attr in &self.attrs {
@@ -397,7 +380,11 @@ impl Content {
}
/// Walks a given value to find any content that matches the selector.
- fn walk_value(value: &Value, selector: &Selector, results: &mut Vec<Content>) {
+ fn walk_value<'a>(
+ value: &'a Value,
+ selector: &Selector,
+ results: &mut Vec<&'a Content>,
+ ) {
match value {
Value::Content(content) => content.query_into(selector, results),
Value::Array(array) => {