Skip to main content

Command

Struct Command 

Source
#[non_exhaustive]
pub struct Command { pub id: CommandId, pub title: String, pub category: String, pub icon: Option<String>, pub description: Option<String>, pub keywords: Vec<String>, pub default_shortcut: Option<KeySequence>, pub when: When, pub state: CommandState, pub args: Option<ArgSchema>, }
Expand description

Metadata for one action.

§Example

use crisol_core::commands::Command;

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§id: CommandId

Stable namespaced identifier.

§title: String

Visible title.

§category: String

Group shown in menus and the palette.

§icon: Option<String>

Optional icon name.

§description: Option<String>

Optional secondary text.

§keywords: Vec<String>

Search terms beyond the title.

§default_shortcut: Option<KeySequence>

The default shortcut.

§when: When

The context in which the command is available.

§state: CommandState

Enabled and checked state.

§args: Option<ArgSchema>

Optional argument schema.

Implementations§

Source§

impl Command

Source

pub fn new(id: impl Into<CommandId>, title: impl Into<String>) -> Self

A command with the default category (General).

Source

pub fn category(self, category: impl Into<String>) -> Self

Set the menu category.

Source

pub fn icon(self, icon: impl Into<String>) -> Self

Set the icon name.

Source

pub fn description(self, description: impl Into<String>) -> Self

Set the secondary text.

Source

pub fn keywords( self, keywords: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Add search terms.

Source

pub fn shortcut(self, shortcut: impl AsRef<str>) -> Self

Set the default shortcut. An invalid string is ignored; use Self::try_shortcut when the caller must see the error.

Source

pub fn try_shortcut( self, shortcut: impl AsRef<str>, ) -> Result<Self, BindingError>

Set the default shortcut and report an invalid string.

Source

pub fn when(self, when: impl AsRef<str>) -> Self

Set the availability context.

Source

pub fn try_when(self, when: impl AsRef<str>) -> Result<Self, BindingError>

Set the availability context and report a parse error.

Source

pub fn args(self, schema: ArgSchema) -> Self

Attach an argument schema.

Source

pub fn is_enabled(&self) -> bool

Whether the command is currently enabled.

Source

pub fn is_checked(&self) -> bool

Whether the command is currently checked.

Source

pub fn applies(&self, context: &WhenContext) -> bool

Whether the command applies in context.

Trait Implementations§

Source§

impl Clone for Command

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Command

Source§

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

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

impl<'de> Deserialize<'de> for Command

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromIterator<Command> for CommandRegistry

Source§

fn from_iter<T: IntoIterator<Item = Command>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl Serialize for Command

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Forget for Command

§

impl Freeze for Command
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<String>: Freeze, PhantomData<KeyChord>: Freeze, *const Expression is !null: Freeze, PhantomData<Expression>: Freeze,

§

impl Move for Command

§

impl RefUnwindSafe for Command

§

impl Send for Command
where RawVecInner: Send, BoxRaw<Expression>: Send,

§

impl Sync for Command
where RawVecInner: Sync, BoxRaw<Expression>: Sync,

§

impl Unpin for Command
where *const u8 is !null: Unpin, Box<Expression>: Unpin,

§

impl UnsafeUnpin for Command

§

impl UnwindSafe for Command
where RawVecInner: UnwindSafe, BoxRaw<Expression>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Key for T
where T: Clone,

Source§

fn align() -> usize

The alignment necessary for the key. Must return a power of two.
Source§

fn size(&self) -> usize

The size of the key in bytes.
Source§

unsafe fn init(&self, ptr: *mut u8)

Initialize the key in the given memory location. Read more
Source§

unsafe fn get<'a>(ptr: *const u8) -> &'a T

Get a reference to the key from the given memory location. Read more
Source§

unsafe fn drop_in_place(ptr: *mut u8)

Drop the key in place. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.