Skip to main content

ObjectDB

Struct ObjectDB 

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

The Object Database.

Port of LaTeXML::Util::ObjectDB. In-memory key-value store. For now, no external DB persistence (the Perl version uses Berkeley DB via DB_File).

Implementations§

Source§

impl ObjectDB

Source

pub fn new() -> Self

Create a new empty ObjectDB.

Source

pub fn adopt_xml(&mut self, node: &Node) -> Option<Value>

Adopt an XML node for storage: deep-copy it into a document the DB owns and return the Value::Xml wrapping the copy. This is the ONLY way a node enters the DB (From<Node> for Value was removed on purpose), so no stored value can dangle into a page document that was freed.

Two hops, because the fork’s copy primitives pull in opposite directions: dup_node_into_new_doc copies from a LINKED source but only into a fresh document, while import_node copies into an EXISTING document but rejects a linked source. So: copy out to a scratch document, detach, copy into the holder, and free the scratch copy — an unlinked doc-owned node is freed by nobody (the rust-libxml Linkage rule behind Node::free_subtree), so dropping the scratch document alone would leak it. A one-hop version wants a fork method that copies from a linked source into an existing document; that is a publish + dep bump, and this is a regression fix.

Returns None when the copy fails; callers should degrade to a string form rather than store nothing, and never crash.

Source

pub fn lookup(&self, key: &str) -> Option<&Entry>

Look up an entry by key.

Port of ObjectDB::lookup.

Source

pub fn lookup_mut(&mut self, key: &str) -> Option<&mut Entry>

Look up an entry by key (mutable).

Source

pub fn register(&mut self, key: &str, props: Vec<(&str, Value)>) -> &mut Entry

Register an entry: create if new, or return existing. Sets the given properties on the entry.

Port of ObjectDB::register.

Source

pub fn unregister(&mut self, key: &str)

Remove an entry.

Port of ObjectDB::unregister.

Source

pub fn get_keys(&self) -> Vec<&String>

Get all keys, sorted.

Port of ObjectDB::getKeys.

Source

pub fn len(&self) -> usize

Number of registered entries. O(1); avoids get_keys().len()’s sort + allocation when only the count is needed.

Source

pub fn is_empty(&self) -> bool

True when no entries are registered.

Source

pub fn keys_iter(&self) -> impl Iterator<Item = &String>

Iterate keys in arbitrary order without allocating/sorting. Use when the traversal order does not matter (e.g. per-node fill-ins).

Source

pub fn status(&self) -> String

Return a status string.

Port of ObjectDB::status.

Source§

impl ObjectDB

Source

pub fn attach(dbfile: &Path, options: DbAttachOptions) -> Result<Self, String>

Attach (and load) an external SQLite object store — Perl ObjectDB->new(dbfile => …).

Source

pub fn save_as(&self, path: &Path) -> Result<usize, String>

Persist this IN-MEMORY db as a fresh dbfile (the parallel-render handoff: the parent scans/sweeps in memory, saves once, and each worker attaches the file readonly). Unlike ObjectDB::finish this does not consume the attachment state — the db stays usable in memory, and any existing file at path is replaced.

Source

pub fn finish(&mut self) -> Result<usize, String>

Write back changed entries and detach — Perl ObjectDB::finish. Returns how many entries were stored. Idempotent: a second call (or a call on a never-attached DB) stores nothing.

Trait Implementations§

Source§

impl Default for ObjectDB

Source§

fn default() -> Self

Returns the “default value” for a type. 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> Same for T

Source§

type Output = T

Should always be Self
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.