Skip to main content

OwnedNodeRef

Struct OwnedNodeRef 

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

A decoded node that owns its decompressed buffer. The inner NodeRef borrows string/byte payloads directly from the buffer, avoiding copies. Container allocations (attribute Vec, child Vec) still occur during decode.

Wrap in Arc<OwnedNodeRef> for cheap sharing across handlers.

Implementations§

Source§

impl OwnedNodeRef

Source

pub fn new(buffer: impl Into<Bytes>) -> Result<Self>

Decode a node from an owned buffer. The buffer should be the raw binary-protocol bytes (after decompression, without the leading format byte which unpack already strips).

Source

pub fn get(&self) -> &NodeRef<'_>

Access the borrowed node.

Source

pub fn to_owned_node(&self) -> Node

Convert to an owned Node, cloning all data out of the buffer. Use sparingly — this is the allocation path that yoke is designed to avoid.

Source

pub fn slice_bytes(&self, slice: &[u8]) -> Bytes

Return a zero-copy Bytes sub-view for a slice that borrows from this node’s backing buffer. Panics if slice does not point within the buffer.

Source

pub fn tag(&self) -> &str

The tag name of this node.

Source

pub fn attrs(&self) -> AttrParserRef<'_>

Get an attribute parser for this node.

Source

pub fn get_attr(&self, key: &str) -> Option<&ValueRef<'_>>

Look up a single attribute by key.

Source

pub fn children(&self) -> Option<&[NodeRef<'_>]>

Get child nodes, if content is a node list.

Source

pub fn get_optional_child(&self, tag: &str) -> Option<&NodeRef<'_>>

Find a child node by tag.

Source

pub fn get_optional_child_by_tag(&self, tags: &[&str]) -> Option<&NodeRef<'_>>

Find a child by traversing a path of tags.

Source

pub fn get_children_by_tag<'b>( &'b self, tag: &'b str, ) -> impl Iterator<Item = &'b NodeRef<'b>>

Get children matching a tag.

Source

pub fn content_bytes(&self) -> Option<&[u8]>

Zero-copy byte content, if this node has Bytes content.

Source

pub fn content_str(&self) -> Option<&str>

Zero-copy string content, if this node has String content.

Source

pub fn content_nodes(&self) -> Option<&[NodeRef<'_>]>

Child nodes from content, if this node has Nodes content.

Source

pub fn content_as_string(&self) -> Option<CompactString>

Extract text content, handling both String and Bytes (lossy UTF-8).

Trait Implementations§

Source§

impl Debug for OwnedNodeRef

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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

impl<T> ErasedDestructor for T
where T: 'static,