Children

Struct Children 

Source
pub struct Children<'a, 'b>(/* private fields */);
Expand description

A thin wrapper around the children of HTMLTag

Implementations§

Source§

impl<'a, 'b> Children<'a, 'b>

Source

pub fn top(&self) -> &RawChildren

Returns the topmost, direct children of this tag.

§Example
let dom = tl::parse(r#"
    <div id="a">
        <div id="b">
            <span>Hello</span>
            <span>World</span>
            <span>.</span>
        </div>
    </div>
"#, Default::default()).unwrap();

let a = dom.get_element_by_id("a")
    .unwrap()
    .get(dom.parser())
    .unwrap()
    .as_tag()
    .unwrap();

// Calling this function on the first div tag (#a) will return a slice containing 3 elements:
// - whitespaces around (before and after) div#b
// - div#b itself
// It does **not** contain the inner span tags
assert_eq!(a.children().top().len(), 3);
Source

pub fn start(&self) -> Option<InnerNodeHandle>

Returns the starting boundary of the children of this tag.

Source

pub fn end(&self, parser: &Parser<'a>) -> Option<InnerNodeHandle>

Returns the ending boundary of the children of this tag.

Source

pub fn boundaries( &self, parser: &Parser<'a>, ) -> Option<(InnerNodeHandle, InnerNodeHandle)>

Returns the (start, end) boundaries of the children of this tag.

Source

pub fn all(&self, parser: &'b Parser<'a>) -> &'b [Node<'a>]

Returns a slice containing all of the children of this HTMLTag, including all subnodes of the children.

The difference between top() and all() is the same as VDom::children() and VDom::nodes()

§Example
let dom = tl::parse(r#"
    <div id="a"><div id="b"><span>Hello</span><span>World</span><span>!</span></div></div>
"#, Default::default()).unwrap();

let a = dom.get_element_by_id("a")
    .unwrap()
    .get(dom.parser())
    .unwrap()
    .as_tag()
    .unwrap();

// Calling this function on the first div tag (#a) will return a slice containing all of the subnodes:
// - div#b
// - span
// - Hello
// - span
// - World
// - span
// - !
assert_eq!(a.children().all(dom.parser()).len(), 7);

Trait Implementations§

Source§

impl<'a, 'b> Clone for Children<'a, 'b>

Source§

fn clone(&self) -> Children<'a, 'b>

Returns a duplicate 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, 'b> Debug for Children<'a, 'b>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, 'b> Freeze for Children<'a, 'b>

§

impl<'a, 'b> RefUnwindSafe for Children<'a, 'b>

§

impl<'a, 'b> !Send for Children<'a, 'b>

§

impl<'a, 'b> !Sync for Children<'a, 'b>

§

impl<'a, 'b> Unpin for Children<'a, 'b>

§

impl<'a, 'b> UnwindSafe for Children<'a, 'b>

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.