pub struct SignRegistry { /* private fields */ }Expand description
The registered sign definitions (SG.1).
Read on the render path (one lookup per placed line) and written rarely (a
provider registering at load), which is the ArcSwap shape every other
contribution registry here uses.
Clone because the ArcSwap write path is copy-on-write: a producer
defining a sign clones the current snapshot, mutates, and stores. The
clone is Vec<Option<Arc<_>>> + the name index — Arc bumps, not glyph
copies — and it happens at registration, never on the render path.
Implementations§
Source§impl SignRegistry
impl SignRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty registry. The host registers the built-ins into it with
register_builtin_signs at boot.
§Examples
use lattice_mode::{SignDefinition, SignRegistry, SIGN_COLUMN_MARK};
let mut signs = SignRegistry::new();
let id = signs.define(SignDefinition {
name: "my-plugin.breakpoint".into(),
text: "\u{f111}".into(), // Nerd Font glyph
fallback: "●".into(), // BMP fallback, same cell width
theme_element: "gutter.sign.breakpoint".into(),
priority: 10,
column: SIGN_COLUMN_MARK.into(),
});
assert_eq!(signs.id_of("my-plugin.breakpoint"), Some(id));
assert_eq!(signs.get(id).unwrap().glyph_char(false), '●');
// Removal retires the id: a stale placement paints nothing.
signs.undefine_prefix("my-plugin.");
assert!(signs.get(id).is_none());
assert!(signs.is_empty());Sourcepub fn define(&mut self, def: SignDefinition) -> SignId
pub fn define(&mut self, def: SignDefinition) -> SignId
Define a sign, or redefine one of the same name.
A redefinition KEEPS the id, so a plugin reloading with a new glyph does not orphan placements already in flight — they simply start painting the new glyph, which is what “redefine” should mean.
Sourcepub fn id_of(&self, name: &str) -> Option<SignId>
pub fn id_of(&self, name: &str) -> Option<SignId>
The id a name resolves to, for a producer turning its own vocabulary into placements.
Sourcepub fn undefine(&mut self, name: &str)
pub fn undefine(&mut self, name: &str)
Forget one, by name. What a plugin’s teardown reverses. The id is retired rather than reused, so an in-flight placement from a producer that ran before the removal paints nothing instead of painting some LATER sign’s glyph.
Sourcepub fn undefine_prefix(&mut self, prefix: &str)
pub fn undefine_prefix(&mut self, prefix: &str)
Forget every sign a namespace defined — org. removes org.mark and
its peers. The unload path, since a plugin’s definitions are not tracked
individually anywhere else.
Sourcepub fn get(&self, id: SignId) -> Option<&Arc<SignDefinition>>
pub fn get(&self, id: SignId) -> Option<&Arc<SignDefinition>>
The definition behind a placement, or None for a retired id — which
paints nothing.
Sourcepub fn iter(&self) -> impl Iterator<Item = (SignId, &Arc<SignDefinition>)>
pub fn iter(&self) -> impl Iterator<Item = (SignId, &Arc<SignDefinition>)>
Every live definition with its id, for a consumer that has to
pre-resolve something per definition — the publish path turning each
theme_element into an ElementId (SG.2b). Skips retired ids, so a
caller never has to re-check get. Order is id order, which is
definition order; nothing here depends on it, but it is stable rather
than hash-dependent, which is the property that keeps such a caller’s
tests from reseeding.
Trait Implementations§
Source§impl Clone for SignRegistry
impl Clone for SignRegistry
Source§fn clone(&self) -> SignRegistry
fn clone(&self) -> SignRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more