Skip to main content

Commands

Struct Commands 

Source
pub struct Commands<H = FnHandler> { /* private fields */ }
Expand description

The commands, by id, each owned.

Implementations§

Source§

impl<H> Commands<H>

Source

pub fn new() -> Self

Source

pub fn register( &mut self, owner: &OwnerId, spec: CommandSpec, handler: H, ) -> Result<(), RegisterError>

Declares a command; a second declaration of an id is refused.

Source

pub fn spec(&self, id: &CommandId) -> Option<&CommandSpec>

Source

pub fn owner(&self, id: &CommandId) -> Option<&OwnerId>

Source

pub fn specs(&self) -> impl Iterator<Item = &CommandSpec>

Every declared command, by id.

Source

pub fn applies(&self, id: &CommandId, cx: &WhenContext) -> bool

Whether a command applies in a context.

Source

pub fn available(&self, cx: &WhenContext) -> Vec<&CommandSpec>

The commands that apply in a context.

Source

pub fn search(&self, query: &str, cx: &WhenContext) -> Vec<&CommandSpec>

Palette commands whose category, title or id contains every word of query, in that context, best first: a title starting with the query, then one with a word starting with each query word, then the rest, each by title.

Source

pub fn prepare( &self, id: &CommandId, cx: &WhenContext, ) -> Result<&H, RunRefused>

The handler of a command that may run here.

Source

pub fn record(&mut self, run: Run)

Keeps a run in the history (the oldest goes past HISTORY).

Source

pub fn history(&self) -> impl Iterator<Item = &Run>

The runs kept, oldest first.

Source

pub fn remove(&mut self, id: &CommandId) -> Option<OwnerId>

Removes one command; returns its owner.

Source

pub fn remove_owner(&mut self, owner: &OwnerId) -> Vec<CommandId>

Removes an owner’s commands; returns their ids.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source§

impl Commands<FnHandler>

Source

pub fn register_fn( &mut self, owner: &OwnerId, spec: CommandSpec, handler: impl Fn(&Json, &Origin) -> Result<Json, String> + Send + Sync + 'static, ) -> Result<(), RegisterError>

Declares a command with a plain handler.

Source

pub fn run( &mut self, id: &CommandId, args: Json, origin: Origin, cx: &WhenContext, ) -> Result<Json, String>

Runs a command; refused when unknown or when it does not apply here. A refusal for an unknown id is not a run and is not kept.

Trait Implementations§

Source§

impl<H> Debug for Commands<H>

Source§

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

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

impl<H> Default for Commands<H>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<H> Freeze for Commands<H>

§

impl<H> RefUnwindSafe for Commands<H>
where H: RefUnwindSafe,

§

impl<H> Send for Commands<H>
where H: Send,

§

impl<H> Sync for Commands<H>
where H: Sync,

§

impl<H> Unpin for Commands<H>

§

impl<H> UnsafeUnpin for Commands<H>

§

impl<H> UnwindSafe for Commands<H>
where H: RefUnwindSafe,

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