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
impl OwnedNodeRef
Sourcepub fn new(buffer: impl Into<Bytes>) -> Result<Self>
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).
Sourcepub fn to_owned_node(&self) -> Node
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.
Sourcepub fn slice_bytes(&self, slice: &[u8]) -> Bytes
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.
Sourcepub fn attrs(&self) -> AttrParserRef<'_>
pub fn attrs(&self) -> AttrParserRef<'_>
Get an attribute parser for this node.
Sourcepub fn get_optional_child(&self, tag: &str) -> Option<&NodeRef<'_>>
pub fn get_optional_child(&self, tag: &str) -> Option<&NodeRef<'_>>
Find a child node by tag.
Sourcepub fn get_optional_child_by_tag(&self, tags: &[&str]) -> Option<&NodeRef<'_>>
pub fn get_optional_child_by_tag(&self, tags: &[&str]) -> Option<&NodeRef<'_>>
Find a child by traversing a path of tags.
Sourcepub fn get_children_by_tag<'b>(
&'b self,
tag: &'b str,
) -> impl Iterator<Item = &'b NodeRef<'b>>
pub fn get_children_by_tag<'b>( &'b self, tag: &'b str, ) -> impl Iterator<Item = &'b NodeRef<'b>>
Get children matching a tag.
Sourcepub fn content_bytes(&self) -> Option<&[u8]>
pub fn content_bytes(&self) -> Option<&[u8]>
Zero-copy byte content, if this node has Bytes content.
Sourcepub fn content_str(&self) -> Option<&str>
pub fn content_str(&self) -> Option<&str>
Zero-copy string content, if this node has String content.
Sourcepub fn content_nodes(&self) -> Option<&[NodeRef<'_>]>
pub fn content_nodes(&self) -> Option<&[NodeRef<'_>]>
Child nodes from content, if this node has Nodes content.
Sourcepub fn content_as_string(&self) -> Option<CompactString>
pub fn content_as_string(&self) -> Option<CompactString>
Extract text content, handling both String and Bytes (lossy UTF-8).