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>
impl<S: Host> Registry<S>
Sourcepub fn new(specs: Vec<CommandSpec<S>>) -> Self
pub fn new(specs: Vec<CommandSpec<S>>) -> Self
Index the table. When an id appears twice the first spec wins (see Registry::duplicates).
Sourcepub fn with_common_params(self, keys: &'static [&'static str]) -> Self
pub fn with_common_params(self, keys: &'static [&'static str]) -> Self
Keys every command accepts on top of its own (document targeting, gesture merging…).
Sourcepub fn with_param_aliases(
self,
aliases: &'static [(&'static str, &'static str)],
) -> Self
pub fn with_param_aliases( self, aliases: &'static [(&'static str, &'static str)], ) -> Self
Alternative spellings legacy text-documented commands accept: (documented, alias).
Sourcepub fn with_validation(self, validation: Validation) -> Self
pub fn with_validation(self, validation: Validation) -> Self
Where the chokepoint validates params (default Validation::Strict).
pub fn validation(&self) -> Validation
pub fn find(&self, id: &str) -> Option<&CommandSpec<S>>
pub fn specs(&self) -> &[CommandSpec<S>]
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn duplicates(&self) -> Vec<&'static str>
pub fn duplicates(&self) -> Vec<&'static str>
Ids declared more than once (a test should assert this is empty).
Sourcepub fn validate(
&self,
spec: &CommandSpec<S>,
params: &Value,
) -> Result<(), CommandError>
pub fn validate( &self, spec: &CommandSpec<S>, params: &Value, ) -> Result<(), CommandError>
Check params against a command’s declaration without running it.
Sourcepub fn schema(&self, id: &str) -> Option<&Value>
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).
Sourcepub fn info(&self, spec: &CommandSpec<S>, state: &S) -> CommandInfo
pub fn info(&self, spec: &CommandSpec<S>, state: &S) -> CommandInfo
Discovery info of one command against the current state (enabled by its own predicate).
Sourcepub fn infos(&self, state: &S) -> Vec<CommandInfo>
pub fn infos(&self, state: &S) -> Vec<CommandInfo>
Discovery info of every command.
Sourcepub fn execute(
&self,
state: &mut S,
id: &str,
params: Value,
) -> Result<Value, CommandError>
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.
Sourcepub fn execute_host(
&self,
state: &mut S,
id: &str,
params: Value,
) -> Result<Value, ExecError<S::Error>>
pub fn execute_host( &self, state: &mut S, id: &str, params: Value, ) -> Result<Value, ExecError<S::Error>>
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).