Skip to main content

ProviderViewRegistry

Struct ProviderViewRegistry 

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

Name → opener, registered at boot and read once per trigger.

Same wait-free shape as ActionHandlerRegistry — copy-on- write registration, Arc load on lookup — because it is the same kind of thing: a table of provider-contributed closures the host consults without knowing what is in them.

Lifetime, amended by MV.1. Native providers register once during subsystem install(&mut boot) and live for the process, which is why there is no RAII token. A PLUGIN’s views do not: a plugin unloads and reloads, so unregister exists for the teardown path. Without it a reload’s register would return false against the plugin’s own stale opener and its views would come back dead.

§Examples

A provider registers its opener at boot; the host looks it up when AppEffect::OpenProviderView { provider: "todo-view", .. } is applied and calls it with itself as the ModeActivator:

use std::sync::Arc;
use lattice_core::{BufferFlags, BufferId, BufferKind};
use lattice_grammar::Args;
use lattice_mode::{
    ModeActivator, ModeId, ProviderViewOpener, ProviderViewOutcome, ProviderViewRegistry,
    ServiceRegistry,
};

let opener: ProviderViewOpener = Arc::new(|host: &mut dyn ModeActivator, _args: &Args| {
    let view = host.ensure_named_document(
        "*todos*",
        ModeId::new("todo-view-mode"),
        BufferFlags::default(),
    );
    ProviderViewOutcome::Opened { view, message: Some("3 todos".into()) }
});

let registry = ProviderViewRegistry::new();
assert!(registry.register("todo-view", opener.clone()));
assert!(!registry.register("todo-view", opener)); // first registration keeps the name

/// A stand-in for the host's `Editor`.
struct Host;
impl ModeActivator for Host {
    fn activate_major_for_kind(&mut self, _: BufferId, _: BufferKind) {}
    fn activate_minor_by_id(&mut self, _: BufferId, _: ModeId) {}
    fn ensure_named_document(&mut self, _: &str, _: ModeId, _: BufferFlags) -> BufferId {
        BufferId(42)
    }
    fn services(&self) -> Arc<ServiceRegistry> {
        Arc::new(ServiceRegistry::new())
    }
}

let open = registry.lookup("todo-view").unwrap();
let outcome = open(&mut Host, &Args::default());
assert_eq!(outcome, ProviderViewOutcome::Opened { view: BufferId(42), message: Some("3 todos".into()) });

Implementations§

Source§

impl ProviderViewRegistry

Source

pub fn new() -> Self

An empty registry. The host registers one as a ProviderViewRegistryHandle at boot.

Source

pub fn register( &self, name: impl Into<String>, opener: ProviderViewOpener, ) -> bool

Register opener under name.

Returns false when name was already taken — and does NOT replace it. Two providers claiming one name is a boot-wiring bug, and last-write-wins would make which view :foo opens depend on install order; refusing lets the caller log the collision while the first registration keeps working.

Source

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

Remove name’s opener, returning whether one was there.

MV.1: the plugin teardown path. Native providers never call it — they outlive every unload — so an unknown name is false rather than a warning.

Source

pub fn lookup(&self, name: &str) -> Option<ProviderViewOpener>

Look up an opener by name. None for an unregistered provider — the host then echoes rather than silently doing nothing.

Source

pub fn names(&self) -> Vec<String>

Registered provider names, sorted. For introspection + tests.

Trait Implementations§

Source§

impl Debug for ProviderViewRegistry

Source§

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

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

impl Default for ProviderViewRegistry

Source§

fn default() -> ProviderViewRegistry

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