Skip to main content

Selection

Struct Selection 

Source
pub struct Selection<'a> { /* private fields */ }
Expand description

A collection of matched nodes from a selector query.

Provides iteration, text extraction, attribute access, and sub-selection (chaining).

Implementations§

Source§

impl<'a> Selection<'a>

Source

pub fn first(&self) -> Option<NodeRef<'a>>

Get the first matched node.

Source

pub fn iter(&self) -> impl Iterator<Item = NodeRef<'a>> + '_

Iterate over matched nodes as NodeRef.

Source

pub fn node_ids(&self) -> &[NodeId]

Iterate over matched node ids.

Source

pub fn text(&self) -> String

Collect text content from all matched nodes.

Source

pub fn attr(&self, name: &str) -> Option<&'a str>

Get an attribute value from the first matched node.

Source

pub fn inner_html(&self) -> String

Get inner HTML from the first matched node.

Source

pub fn len(&self) -> usize

Number of matched nodes.

Source

pub fn is_empty(&self) -> bool

Whether the selection is empty.

Source

pub fn select_compiled( &self, sel: &CompiledSelector, ) -> Result<Selection<'a>, SelectorError>

Sub-select with a pre-compiled selector within the matched nodes.

Each matched node is used as a subtree root, and results are deduplicated in document order.

Source

pub fn select(&self, css: &str) -> Result<Selection<'a>, SelectorError>

Sub-select: run a CSS selector within the matched nodes.

Each matched node is used as a subtree root, and results are deduplicated in document order.

Source

pub fn xpath(&self, expr: &str) -> Result<XPathResult, XPathError>

Evaluate an XPath expression within the matched nodes.

Each matched node is used as a context root, and results are deduplicated in document order.

Trait Implementations§

Source§

impl<'a> IntoIterator for &'a Selection<'a>

Source§

type Item = NodeRef<'a>

The type of the elements being iterated over.
Source§

type IntoIter = SelectionIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Selection<'a>

§

impl<'a> RefUnwindSafe for Selection<'a>

§

impl<'a> Send for Selection<'a>

§

impl<'a> Sync for Selection<'a>

§

impl<'a> Unpin for Selection<'a>

§

impl<'a> UnsafeUnpin for Selection<'a>

§

impl<'a> UnwindSafe for Selection<'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> 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, 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.