Struct ChildrenFetch

Source
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>

Source

pub fn for_node(node: &'a Node) -> Self

Get children fetcher for given node to find children that apply to some criteria.

Source

pub fn same_for_node(&self, node: &'a Node) -> Self

Clone the fetcher with already set criteria but for given different node.

Source

pub fn tag(self, tag: &'a str) -> Self

Tag to search for.

Source

pub fn set_tag(&mut self, tag: &'a str)

Source

pub fn key(self, key: &'a str) -> Self

Key to search for.

Source

pub fn set_key(&mut self, key: &'a str)

Source

pub fn value(self, value: &'a str) -> Self

Exact value to search for.

Source

pub fn set_value(&mut self, value: &'a str)

Source

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.

Source

pub fn set_value_part(&mut self, part: &'a str)

Source

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>

Source§

fn clone(&self) -> ChildrenFetch<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ChildrenFetch<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.