Skip to main content

Registry

Struct Registry 

Source
pub struct Registry<S: Host> { /* private fields */ }
Expand description

The command table of one app. Immutable once built (a static is typical); the execution state lives in the host’s crate::Journal.

Implementations§

Source§

impl<S: Host> Registry<S>

Source

pub fn new(specs: Vec<CommandSpec<S>>) -> Self

Index the table. When an id appears twice the first spec wins (see Registry::duplicates).

Source

pub fn with_common_params(self, keys: &'static [&'static str]) -> Self

Keys every command accepts on top of its own (document targeting, gesture merging…).

Source

pub fn with_param_aliases( self, aliases: &'static [(&'static str, &'static str)], ) -> Self

Alternative spellings legacy text-documented commands accept: (documented, alias).

Source

pub fn with_validation(self, validation: Validation) -> Self

Where the chokepoint validates params (default Validation::Strict).

Source

pub fn validation(&self) -> Validation

Source

pub fn find(&self, id: &str) -> Option<&CommandSpec<S>>

Source

pub fn specs(&self) -> &[CommandSpec<S>]

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn duplicates(&self) -> Vec<&'static str>

Ids declared more than once (a test should assert this is empty).

Source

pub fn validate( &self, spec: &CommandSpec<S>, params: &Value, ) -> Result<(), CommandError>

Check params against a command’s declaration without running it.

Source

pub fn schema(&self, id: &str) -> Option<&Value>

The JSON Schema of a command’s parameters (computed once for the whole table, on first use).

Source

pub fn info(&self, spec: &CommandSpec<S>, state: &S) -> CommandInfo

Discovery info of one command against the current state (enabled by its own predicate).

Source

pub fn infos(&self, state: &S) -> Vec<CommandInfo>

Discovery info of every command.

Source

pub fn execute( &self, state: &mut S, id: &str, params: Value, ) -> Result<Value, CommandError>

The one chokepoint every caller goes through (UI, menus, palette, shortcuts, CLI, control port, MCP, and commands running other commands). See Host for the order of steps. Host errors come back converted into CommandError; Registry::execute_host keeps them.

Source

pub fn execute_host( &self, state: &mut S, id: &str, params: Value, ) -> Result<Value, ExecError<S::Error>>
where S::Error: Clone,

Registry::execute for a host whose callers match on its own error type: an error a command body returned comes back unchanged as ExecError::Host; a refusal or failure of the chokepoint itself (unknown, too deep, validation, disabled, panic) is ExecError::Command. An error from Host::before is the host’s too: Host. Same steps and hooks; Host::after still sees the error converted into a CommandError (hence Clone: the original is kept for the caller).

Source

pub fn bind<'a>(&'a self, state: &'a mut S) -> Bound<'a, S>

Bind the table to a state: a Dispatch for discovery and execution.

Auto Trait Implementations§

§

impl<S> !Freeze for Registry<S>

§

impl<S> RefUnwindSafe for Registry<S>

§

impl<S> Send for Registry<S>
where Vec<CommandSpec<S>>: Send,

§

impl<S> Sync for Registry<S>
where Vec<CommandSpec<S>>: Sync,

§

impl<S> Unpin for Registry<S>
where Vec<CommandSpec<S>>: Unpin,

§

impl<S> UnsafeUnpin for Registry<S>

§

impl<S> UnwindSafe for Registry<S>

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.

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

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.