pub struct CommandRegistry { /* private fields */ }Expand description
Maps a command name to the handler that runs it - built fresh by
whatever calls CommandRegistry::dispatch (typically the generated
app’s own main.rs, via routes::console::commands()), not a
process-wide static: exactly one process ever reads it, for exactly
as long as that one xr <command> invocation runs, so there’s no
cross-request sharing need the way larust-events’ listener registry
or larust_http::route’s named-route registry have.
Implementations§
Source§impl CommandRegistry
impl CommandRegistry
pub fn new() -> CommandRegistry
Sourcepub fn register<C>(self) -> CommandRegistrywhere
C: Command,
pub fn register<C>(self) -> CommandRegistrywhere
C: Command,
Registers C under its own Command::NAME. Panics on a duplicate
name - a startup-time registration collision is a real programmer
bug (the shadowed command would silently never run again); failing
loudly and immediately here beats a confusing “why did xr report:posts just run the wrong thing” bug report later, the same
reasoning JobRegistry::register’s own duplicate check already
established for this codebase.
Sourcepub async fn dispatch(
&self,
name: &str,
args: &[String],
) -> Result<bool, AppError>
pub async fn dispatch( &self, name: &str, args: &[String], ) -> Result<bool, AppError>
Runs the named command with args, returning Ok(true) if a
command with that name was actually registered and run, or
Ok(false) if nothing matched. false, not an error - the
distinction lets a caller (main.rs’s own dispatch chain) fall
through to its own “unknown command” handling for a name that
matches neither a registered Command nor one of the framework’s
own fixed subcommands (migrate, queue:work, …), rather than
this crate having to know about those at all.
Sourcepub fn list(&self) -> Vec<CommandInfo>
pub fn list(&self) -> Vec<CommandInfo>
Every registered command’s name and description, sorted by name -
for xr command:list to print in a stable, predictable order
rather than HashMap’s own unspecified iteration order.
Trait Implementations§
Source§impl Default for CommandRegistry
impl Default for CommandRegistry
Source§fn default() -> CommandRegistry
fn default() -> CommandRegistry
Auto Trait Implementations§
impl !RefUnwindSafe for CommandRegistry
impl !UnwindSafe for CommandRegistry
impl Freeze for CommandRegistry
impl Send for CommandRegistry
impl Sync for CommandRegistry
impl Unpin for CommandRegistry
impl UnsafeUnpin for CommandRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more