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
impl ObjectDB
Sourcepub fn adopt_xml(&mut self, node: &Node) -> Option<Value>
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.
Sourcepub fn lookup(&self, key: &str) -> Option<&Entry>
pub fn lookup(&self, key: &str) -> Option<&Entry>
Look up an entry by key.
Port of ObjectDB::lookup.
Sourcepub fn lookup_mut(&mut self, key: &str) -> Option<&mut Entry>
pub fn lookup_mut(&mut self, key: &str) -> Option<&mut Entry>
Look up an entry by key (mutable).
Sourcepub fn register(&mut self, key: &str, props: Vec<(&str, Value)>) -> &mut Entry
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.
Sourcepub fn unregister(&mut self, key: &str)
pub fn unregister(&mut self, key: &str)
Remove an entry.
Port of ObjectDB::unregister.
Sourcepub fn len(&self) -> usize
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§impl ObjectDB
impl ObjectDB
Sourcepub fn attach(dbfile: &Path, options: DbAttachOptions) -> Result<Self, String>
pub fn attach(dbfile: &Path, options: DbAttachOptions) -> Result<Self, String>
Attach (and load) an external SQLite object store — Perl
ObjectDB->new(dbfile => …).
Sourcepub fn save_as(&self, path: &Path) -> Result<usize, String>
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.