pub struct CommandRegistry { /* private fields */ }Expand description
Thread-safe registry of known Tauri commands, indexed by name.
Implementations§
Source§impl CommandRegistry
impl CommandRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty command registry.
use victauri_core::CommandRegistry;
let registry = CommandRegistry::new();
assert_eq!(registry.count(), 0);
assert!(registry.list().is_empty());Sourcepub fn register(&self, info: CommandInfo)
pub fn register(&self, info: CommandInfo)
Registers a command, replacing any existing entry with the same name.
use victauri_core::{CommandRegistry, CommandInfo};
let registry = CommandRegistry::new();
registry.register(CommandInfo::new("greet").with_description("Say hello"));
assert_eq!(registry.count(), 1);
assert!(registry.get("greet").is_some());Sourcepub fn get(&self, name: &str) -> Option<CommandInfo>
pub fn get(&self, name: &str) -> Option<CommandInfo>
Looks up a command by exact name.
Sourcepub fn list(&self) -> Vec<CommandInfo>
pub fn list(&self) -> Vec<CommandInfo>
Returns all registered commands in alphabetical order.
Sourcepub fn search(&self, query: &str) -> Vec<CommandInfo>
pub fn search(&self, query: &str) -> Vec<CommandInfo>
Searches commands by substring match on name or description (case-insensitive).
§Examples
use victauri_core::{CommandRegistry, CommandInfo};
let registry = CommandRegistry::new();
registry.register(
CommandInfo::new("get_settings").with_description("Retrieve app settings"),
);
let results = registry.search("settings");
assert_eq!(results.len(), 1);
assert_eq!(results[0].name, "get_settings");Sourcepub fn resolve(&self, query: &str) -> Vec<ScoredCommand>
pub fn resolve(&self, query: &str) -> Vec<ScoredCommand>
Resolves a natural-language query to commands ranked by relevance score.
§Examples
use victauri_core::{CommandRegistry, CommandInfo};
let registry = CommandRegistry::new();
registry.register(
CommandInfo::new("get_settings")
.with_description("Retrieve app settings")
.with_intent("fetch configuration")
.with_category("settings"),
);
let results = registry.resolve("get settings");
assert!(!results.is_empty());
assert!(results[0].score > 0.0);Source§impl CommandRegistry
impl CommandRegistry
Sourcepub fn from_auto_discovery() -> Self
pub fn from_auto_discovery() -> Self
Creates a registry pre-populated with all #[inspectable] commands.
Uses inventory to collect every CommandInfo that was submitted at
link time by the #[inspectable] macro. This replaces manual
register_commands! or .commands(&[...]) calls.
use victauri_core::CommandRegistry;
let registry = CommandRegistry::from_auto_discovery();
// Contains all #[inspectable] commands from the binaryTrait Implementations§
Source§impl Clone for CommandRegistry
impl Clone for CommandRegistry
Source§fn clone(&self) -> CommandRegistry
fn clone(&self) -> CommandRegistry
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CommandRegistry
impl Debug for CommandRegistry
Auto Trait Implementations§
impl Freeze for CommandRegistry
impl RefUnwindSafe for CommandRegistry
impl Send for CommandRegistry
impl Sync for CommandRegistry
impl Unpin for CommandRegistry
impl UnsafeUnpin for CommandRegistry
impl UnwindSafe 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
Mutably borrows from an owned value. Read more