Skip to main content

ModelineService

Struct ModelineService 

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

Shared modeline service: descriptor registry + content store, each behind an [ArcSwap] for wait-free reads and lock-free updates. The host holds an Arc and reads Self::snapshot each build_render_state; modes/plugins hold the same Arc (via ctx.service::<ModelineServiceHandle>(), ML.0b-2 / ML.3) and register / remove descriptors. Content normally arrives as a ModelineElementUpdate on the event bus, which also wakes the render; calling update directly changes the store without a wake.

§Examples

use lattice_core::BufferId;
use lattice_mode::{
    ElementContent, ElementId, ModelineElement, ModelineKey, ModelineRole, ModelineService,
    Zone,
};

let service = ModelineService::new();
let id = ElementId::new("my-plugin.count");
service.register(ModelineElement::new(id.clone(), Zone::Right, 50));
service.update(
    ModelineKey::Buffer(BufferId(7)),
    id.clone(),
    ElementContent::text("3 todos", ModelineRole::new("modeline.mode_item")),
);

let snap = service.snapshot();
let right = snap.zone(Zone::Right, BufferId(7));
assert_eq!(right[0].1.plain(), "3 todos");
// Pane-local content is per buffer: another buffer's pane shows nothing.
assert!(snap.zone(Zone::Right, BufferId(8)).is_empty());

Mirrors ActionHandlerRegistry’s ArcSwap shape — content updates may arrive from a mode’s spawned task on another thread, so the store must be Sync.

Implementations§

Source§

impl ModelineService

Source

pub fn new() -> Self

An empty service (no descriptors, no content). The host builds one and registers it as a ModelineServiceHandle.

Source

pub fn register(&self, element: ModelineElement)

Register (or replace) a descriptor. Owner-scoped by the id namespace (§6); last-write-wins.

Source

pub fn remove(&self, id: &ElementId)

Remove a descriptor (idempotent).

Source

pub fn update(&self, key: ModelineKey, id: ElementId, content: ElementContent)

Set an element’s content under (key, id). An update for an id with no descriptor is harmless — it simply won’t render until one is registered. key selects the pane (Buffer) or global slot (§4 per-pane content resolution).

Source

pub fn clear(&self, key: ModelineKey, id: &ElementId)

Clear an element’s content under (key, id) (hides it). Idempotent.

Source

pub fn apply(&self, update: ModelineElementUpdate)

Apply a pushed ModelineElementUpdate (the actor-thread drain’s per-event step, ML.3): empty content clears the slot (hidden), non-empty content sets it. Routing empty → clear keeps the store from accumulating dead entries as producers toggle visibility.

Source

pub fn snapshot(&self) -> ModelineSnapshot

Wait-free snapshot for the renderer (two Arc clones).

Trait Implementations§

Source§

impl Debug for ModelineService

Source§

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

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

impl Default for ModelineService

Source§

fn default() -> ModelineService

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