pub struct ChildrenFetch<'a> { /* private fields */ }
Expand description
Settings to fetch children nodes that apply to given criteria.
§Examples
let html = r#"
<div id="mydiv">
<p class="someclass">Text</p>
</div>
<a class="someclass else">link</a>
"#;
// Create node tree for HTML code.
let node = Node::from_html(html, &Default::default()).unwrap().unwrap();
// Create criteria. Find all `div` nodes with `id='mydiv'`.
let fetch = node.children_fetch()
.tag("div")
.key("id")
.value("mydiv");
// Search for all children that apply to criteria.
let result = fetch.fetch();
// Returns the first node: `<div id='mydiv'>`.
assert_eq!(result.iter().nth(0).unwrap(), &node.children().get(0).unwrap());
// Search for all with class='someclass' allowing it to contain other classes too.
let fetch = node.children_fetch()
.key("class")
.value_part("someclass");
let result = fetch.fetch();
// Returns the nodes <p> and <a>.
assert_eq!(result.iter().nth(0).unwrap(),
&node.children().get(0).unwrap().children().get(0).unwrap());
assert_eq!(result.iter().nth(1).unwrap(), &node.children().get(1).unwrap());
Implementations§
Source§impl<'a> ChildrenFetch<'a>
impl<'a> ChildrenFetch<'a>
Sourcepub fn for_node(node: &'a Node) -> Self
pub fn for_node(node: &'a Node) -> Self
Get children fetcher for given node to find children that apply to some criteria.
Sourcepub fn same_for_node(&self, node: &'a Node) -> Self
pub fn same_for_node(&self, node: &'a Node) -> Self
Clone the fetcher with already set criteria but for given different node.
pub fn set_tag(&mut self, tag: &'a str)
pub fn set_key(&mut self, key: &'a str)
pub fn set_value(&mut self, value: &'a str)
Sourcepub fn value_part(self, part: &'a str) -> Self
pub fn value_part(self, part: &'a str) -> Self
If exact value is not set then this defines a part of the value separated with whitespaces
to be found. If value
is, however, set then this field is ignored entirely.
pub fn set_value_part(&mut self, part: &'a str)
Sourcepub fn fetch(self) -> LinkedList<&'a NodeAccess>
pub fn fetch(self) -> LinkedList<&'a NodeAccess>
Get all children and their children that apply to the criteria. This function does not check the parent node!
Trait Implementations§
Source§impl<'a> Clone for ChildrenFetch<'a>
impl<'a> Clone for ChildrenFetch<'a>
Source§fn clone(&self) -> ChildrenFetch<'a>
fn clone(&self) -> ChildrenFetch<'a>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<'a> Debug for ChildrenFetch<'a>
impl<'a> Debug for ChildrenFetch<'a>
impl<'a> Copy for ChildrenFetch<'a>
Auto Trait Implementations§
impl<'a> Freeze for ChildrenFetch<'a>
impl<'a> RefUnwindSafe for ChildrenFetch<'a>
impl<'a> Send for ChildrenFetch<'a>
impl<'a> Sync for ChildrenFetch<'a>
impl<'a> Unpin for ChildrenFetch<'a>
impl<'a> UnwindSafe for ChildrenFetch<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more