Skip to main content

Index

Struct Index 

Source
pub struct Index { /* private fields */ }
Expand description

The index of one version of a tree. Its owner builds it once and keeps it until the tree changes: every query reads it, none builds it.

Implementations§

Source§

impl Index

Source

pub fn build(tree: &Document, roots: &[u32]) -> Index

Indexes the tree under each of roots in turn: the document, then any subtrees removed from it or built apart from it, so every node a caller can hold has a position.

Source

pub fn len(&self) -> usize

How many nodes are indexed.

Source

pub fn is_empty(&self) -> bool

Source

pub fn order(&self, id: u32) -> u32

A node’s position; u32::MAX if it was made after the index was.

Source

pub fn node_at(&self, at: u32) -> u32

The node at position at.

Source

pub fn kind_at(&self, at: u32) -> u8

The kind (ELEMENT, TEXT and so on) at position at.

Source

pub fn tag_at(&self, at: u32) -> usize

The tag id at position at.

Source

pub fn tag_id_named(&self, name: &str) -> Option<usize>

The tag id elements named name (compared lowercased) carry, if any element could: a known tag’s always, another name’s only when some element in the document has it.

Source

pub fn with_id<'t>( &self, id: &str, id_of: impl Fn(u32) -> Option<&'t str>, ) -> Vec<u32>

The elements whose id is id, in document order. id_of reads a node’s id attribute; the first call’s is used for every call.

Source

pub fn descendants( &self, at: u32, include_self: bool, keep: impl Fn(u8, usize) -> bool, out: &mut Vec<u32>, )

Appends to out the nodes below at (from at itself if include_self) that pass keep(kind, tag), in document order.

Source

pub fn end_of(&self, at: u32) -> u32

One past the last descendant of at.

Source

pub fn parent_of(&self, at: u32) -> u32

The position of the parent of the node at at; u32::MAX for a root.

Source

pub fn children( &self, at: u32, keep: impl Fn(u8, usize) -> bool, out: &mut Vec<u32>, )

Appends to out the children of at that pass keep(kind, tag).

Auto Trait Implementations§

§

impl !Freeze for Index

§

impl Forget for Index

§

impl Move for Index

§

impl RefUnwindSafe for Index

§

impl Send for Index

§

impl Sync for Index

§

impl Unpin for Index

§

impl UnsafeUnpin for Index

§

impl UnwindSafe for Index

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.