Skip to main content

Module atom

Module atom 

Source
Expand description

String interning for names that cross a guest boundary.

Nothing in this crate requires an AtomId yet. It exists now because the next binding hosts a guest that cannot cheaply pass strings, and the names it will pass most are the ones with the smallest alphabets: tag names, attribute names, and class values.

§Ownership rule

An Interner is owned by the binding, one per document. An AtomId is only meaningful against the interner that produced it; resolving one against any other interner is DomError::UnknownAtom at best and a silently wrong name at worst. Do not store an AtomId alongside a document without also storing which interner it belongs to.

§Why the operations still take &str

The binding resolves at its own boundary and calls the operation with the resolved string:

let mut names = Interner::new();
let class = names.intern("panel");
// ... the guest hands back `class` some time later ...
let name = names.resolve(class).unwrap();
assert_eq!(name, "panel");

Threading the interner through every operation instead would put a second parameter on the whole API to serve one caller, and would still not remove the resolve, only move it. Resolving one level up keeps these signatures stable for whichever guest arrives, which is the property that mattered.

Structs§

AtomId
A name interned by an Interner.
Interner
A set of interned names, owned by the binding.