Skip to main content

InMemoryThemeRegistry

Struct InMemoryThemeRegistry 

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

In-memory ThemeRegistry. Holds the element table + active palette behind an RwLock, and the resolved read table behind an ArcSwap for lock-free reads.

Implementations§

Source§

impl InMemoryThemeRegistry

Source

pub fn new(palette: Palette) -> Self

Empty registry with the given palette. Register elements, then resolved() builds the table on first read.

Source

pub fn with_defaults() -> Self

Registry seeded with the default palette + all builtin core elements, resolved and ready. The T.3 boot path + tests use this.

Source

pub fn set_palette(&self, palette: Palette)

Replace the active palette (a :colorscheme / :set ui.* path lands in T.9). Marks the table dirty.

Source

pub fn rebuild(&self)

Re-resolve every element into a fresh ResolvedTheme and publish it. Called on dirty reads; O(elements), theme-build time only (never on the hot path).

Trait Implementations§

Source§

impl ThemeRegistry for InMemoryThemeRegistry

Source§

fn register( &self, name: ElementName, owner: ElementOwner, default: StyleSpec, doc: &'static str, ) -> ElementId

Register an element with its owner-supplied default. Idempotent by name — re-registering an existing name returns the existing id and leaves its default unchanged.
Source§

fn id(&self, name: &ElementName) -> Option<ElementId>

The interned id for a name, if registered.
Source§

fn unregister_element(&self, name: &ElementName) -> bool

TC.4: withdraw an element by name — the reverse of Self::register, used when a plugin unloads. Returns whether a name was removed (idempotent: a second unload removes nothing). Read more
Source§

fn resolved(&self) -> Arc<ResolvedTheme> ⓘ

The current resolved read table (rebuilt lazily if a registration / palette change left it dirty).
Source§

fn set_override(&self, name: ElementName, spec: StyleSpec)

T.9: set (or replace) the theme-global override for an element (:set ui.*, user TOML, a theme’s override list). Overlays the override’s set fields on the element’s resolved default. Marks the table dirty (re-resolved on next resolved()).
Source§

fn set_theme(&self, palette: Palette, overrides: Vec<(ElementName, StyleSpec)>)

T.9: swap the active theme — replace the palette AND the full override set atomically (:colorscheme). Prior overrides are cleared. Marks the table dirty.
Source§

fn register_theme(&self, theme: NamedTheme)

T.11.1: register (or replace, by name) a named theme in the catalog. Idempotent by name — re-registering a name replaces its palette + overrides. This is the seam init.rs (and, later, a WASM plugin via WIT) uses to contribute a palette; the builtin themes are seeded here at boot. Does NOT change the active theme — only apply_theme does that.
Source§

fn theme_names(&self) -> Vec<String>

T.11.1: the names of every registered theme, in registration order (builtins first, then user/plugin additions). Drives :colorscheme completion + the T.12 picker.
Source§

fn element_names(&self) -> Vec<String>

T.9.d follow-up: the names of every registered theme element, sorted. Drives :describe-element / :describe-face <Tab> completion (the gen:elements host generator). Sorted so popup ordering is stable across runs; a theme-build-time read, never on the hot path.
Source§

fn apply_theme(&self, name: &str) -> bool

T.11.1: swap the active theme to the registered theme name (:colorscheme <name>). Returns false (active theme untouched) if name is not registered — the caller echoes an error, never a panic. On a hit, equivalent to set_theme with the registered theme’s palette + overrides (marks the table dirty).
Source§

fn active_theme(&self) -> (Palette, Vec<(ElementName, StyleSpec)>)

T.12a: snapshot the active palette + the active theme-global override set as a (Palette, Vec<(ElementName, StyleSpec)>) pair. The colorscheme picker captures this on the first live preview so <Esc> can restore the theme active when the picker opened via Self::set_theme. Cheap clone of the inner state under a read lock; no resolution.
Source§

fn describe(&self, name: &ElementName) -> Option<ElementInfo>

T.9.d: element metadata for introspection (:describe-element / :describe-face). Returns the element’s identity + owner + authoring default + doc + concrete resolved style, or None if name is not a registered element. Reads the resolved table (rebuilding it lazily if dirty) so the resolved field reflects the active theme — a theme-build-time read, never on the hot path.

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.

§

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, 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