Skip to main content

Dict

Struct Dict 

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

A refcounted per-document string interner.

Never construct directly with Dict { ... } — use Dict::new_refcounted which guarantees the heap allocation and initial refcount of 1. Internally not Send/Sync despite the atomic refcount: the RefCell guarding the table is single- threaded. C-ABI consumers (libxml2) are GIL-protected on the Python side and single-thread the dict accordingly.

Implementations§

Source§

impl Dict

Source

pub fn new_refcounted() -> *mut Dict

Allocate a fresh dict on the heap. Refcount starts at 1 (the caller’s reference). Returns a raw pointer; callers must eventually balance with Dict::release.

Source

pub unsafe fn new_sub(parent: *mut Dict) -> *mut Dict

Allocate a sub-dictionary chained to parent (libxml2 xmlDictCreateSub). The sub-dict shares the parent’s interned strings — see the parent field — and takes one reference to it, released when the sub-dict is freed. A NULL parent is equivalent to new_refcounted.

§Safety

parent must be NULL or a live Dict* on which the caller can take a reference.

Source

pub fn retain_arena(&self, arena: Arc<Bump>)

Retain arena (an origin document’s node arena) so a node moved out of it — whose name re-interned into this dict during a cross-thread graft — outlives a drop of its origin document. Deduped by pointer, so repeated grafts from one source arena keep a single entry. The caller guarantees arena is not the destination’s own (a same-arena move needs no retention).

Source

pub fn add_ref(&self)

Increment the refcount. Use when copying a *mut Dict to a new owner. Cheap atomic op.

Source

pub unsafe fn release(ptr: *mut Dict) -> bool

Decrement the refcount. When the last reference goes away, drops every interned string and the dict itself. Returns true if this call was the one that freed.

§Safety

ptr must be a non-null pointer previously returned by Dict::new_refcounted, and the caller must own one reference (i.e. exactly one outstanding add_ref not yet paired with a release).

Source

pub fn refcount(&self) -> usize

Current refcount. For tests + debugging; not load-bearing.

Source

pub fn intern(&self, input: &[u8]) -> *const u8

Look up input, inserting if absent. Returns the canonical NUL-terminated pointer.

Source

pub fn intern_str(&self, s: &str) -> *const u8

&str-keyed convenience over Self::intern.

Source

pub fn lookup(&self, input: &[u8]) -> *const u8

Non-allocating lookup. Returns the canonical pointer on hit, NULL on miss.

Source

pub fn owns(&self, ptr: *const u8) -> bool

Does ptr originate from this dict or any ancestor? libxml2’s xmlDictOwns walks the sub-dict chain, so a string interned in the parent is “owned” when probed through a child.

Source

pub fn len(&self) -> usize

Number of distinct strings interned.

Source

pub fn is_empty(&self) -> bool

Auto Trait Implementations§

§

impl !Freeze for Dict

§

impl !Send for Dict

§

impl !Sync for Dict

§

impl RefUnwindSafe for Dict

§

impl Unpin for Dict

§

impl UnsafeUnpin for Dict

§

impl UnwindSafe for Dict

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.