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 of node bytes: after decompression and without the format byte, which unpack strips. A buffer that still carries it goes through unpack first.

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 backing_bytes(&self) -> Bytes

The whole backing buffer, verbatim: exactly what Self::new consumed.

A refcount bump, not a copy — the yoke already retains this buffer, and Self::slice_bytes hands out views into the same allocation.

These are node bytes, so they are not a sendable frame: send paths take a packed payload, one format byte in front of the node bytes, which unpack stripped on the way in. Put it back with pack before forwarding these bytes anywhere that expects marshal output.

Re-encoding through marshal_ref is the alternative and a worse one for anything that forwards a stanza onward — to another process, a recording, a replay harness. Re-encoding costs a second pass and is only faithful while the token dictionaries match the ones that decoded it; these bytes stay true whatever the dictionaries do.

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§

§

impl !Freeze for OwnedNodeRef

§

impl Forget for OwnedNodeRef

§

impl Move for OwnedNodeRef

§

impl RefUnwindSafe for OwnedNodeRef

§

impl Send for OwnedNodeRef
where &'static str: Send, Repr: Send, BoxRaw<[(NodeStr<'static>, ValueRef<'static>)]>: Send, &'static [u8]: Send, Vec<u8>: Send, BoxRaw<[NodeRef<'static>]>: Send, Bytes: Send,

§

impl Sync for OwnedNodeRef
where Repr: Sync, BoxRaw<[(NodeStr<'static>, ValueRef<'static>)]>: Sync, Vec<u8>: Sync, BoxRaw<[NodeRef<'static>]>: Sync, Bytes: Sync,

§

impl Unpin for OwnedNodeRef
where &'static str: Unpin, *const (): Unpin, Box<[(NodeStr<'static>, ValueRef<'static>)]>: Unpin, &'static [u8]: Unpin, Vec<u8>: Unpin, Box<[NodeRef<'static>]>: Unpin, *const u8: Unpin, Align8<*mut ()>: Unpin, &'static Vtable: Unpin,

§

impl UnsafeUnpin for OwnedNodeRef
where &'static str: UnsafeUnpin, *const (): UnsafeUnpin, *const [(NodeStr<'static>, ValueRef<'static>)] is !null: UnsafeUnpin, PhantomData<[(NodeStr<'static>, ValueRef<'static>)]>: UnsafeUnpin, &'static [u8]: UnsafeUnpin, Vec<u8>: UnsafeUnpin, *const [NodeRef<'static>] is !null: UnsafeUnpin, PhantomData<[NodeRef<'static>]>: UnsafeUnpin, *const u8: UnsafeUnpin, Align8<*mut ()>: UnsafeUnpin, &'static Vtable: UnsafeUnpin,

§

impl UnwindSafe for OwnedNodeRef
where &'static str: UnwindSafe, *const (): UnwindSafe, BoxRaw<[(NodeStr<'static>, ValueRef<'static>)]>: UnwindSafe, &'static [u8]: UnwindSafe, Vec<u8>: UnwindSafe, BoxRaw<[NodeRef<'static>]>: UnwindSafe, *const u8: UnwindSafe, Align8<*mut ()>: UnwindSafe, &'static Vtable: UnwindSafe,

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> ErasedDestructor for T
where T: 'static,

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.