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
impl ModelineService
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty service (no descriptors, no content). The host builds one
and registers it as a ModelineServiceHandle.
Sourcepub fn register(&self, element: ModelineElement)
pub fn register(&self, element: ModelineElement)
Register (or replace) a descriptor. Owner-scoped by the id
namespace (§6); last-write-wins.
Sourcepub fn update(&self, key: ModelineKey, id: ElementId, content: ElementContent)
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).
Sourcepub fn clear(&self, key: ModelineKey, id: &ElementId)
pub fn clear(&self, key: ModelineKey, id: &ElementId)
Clear an element’s content under (key, id) (hides it). Idempotent.
Sourcepub fn apply(&self, update: ModelineElementUpdate)
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.
Sourcepub fn snapshot(&self) -> ModelineSnapshot
pub fn snapshot(&self) -> ModelineSnapshot
Wait-free snapshot for the renderer (two Arc clones).