Skip to main content

SignRegistry

Struct SignRegistry 

Source
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

Source

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());
Source

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.

Source

pub fn id_of(&self, name: &str) -> Option<SignId>

The id a name resolves to, for a producer turning its own vocabulary into placements.

Source

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.

Source

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.

Source

pub fn get(&self, id: SignId) -> Option<&Arc<SignDefinition>>

The definition behind a placement, or None for a retired id — which paints nothing.

Source

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.

Source

pub fn len(&self) -> usize

How many definitions are live. Retired ids do not count.

Source

pub fn is_empty(&self) -> bool

True when no definition is live (every id retired or none defined).

Trait Implementations§

Source§

impl Clone for SignRegistry

Source§

fn clone(&self) -> SignRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SignRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SignRegistry

Source§

fn default() -> SignRegistry

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more