Skip to main content

CommandSpec

Struct CommandSpec 

Source
#[non_exhaustive]
pub struct CommandSpec {
Show 19 fields pub id: CommandId, pub title: String, pub category: String, pub description: String, pub when: String, pub checked: String, pub keys: Vec<KeySpec>, pub menus: Vec<MenuPlacement>, pub palette: bool, pub agent: bool, pub read_only: bool, pub destructive: bool, pub destructive_if: Vec<ArgMatch>, pub private: bool, pub args: Value, pub icon: Option<String>, pub icon_on: Option<String>, pub menu_note: Option<String>, pub opens_link: bool,
}
Expand description

What a command declares.

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, never translated: view.palette.

§title: String§category: String§description: String

What it does, for the palette and agents.

§when: String

Where the command applies; empty: everywhere.

§checked: String

When its menu entries show ticked (a toggle that is on, the theme in use); empty: never.

§keys: Vec<KeySpec>

Its default key bindings (Ctrl+K, Ctrl+K Ctrl+S).

§menus: Vec<MenuPlacement>

Its menu entries.

§palette: bool

Listed in the command palette.

§agent: bool

Offered to agents through the debug bridge.

§read_only: bool

It only reads: running it changes nothing in the application (about.read, value.get). The debug bridge reports it (commands.run does not mutate then) and a read-only bridge runs only these.

§destructive: bool

It destroys or discards what cannot easily be had back (deletes files, empties a trash, drops unsaved work). Asked by anyone but the user (an agent), it waits for the user to confirm it first: the agent socket asks, through a dialog. The user’s own runs are never asked.

§destructive_if: Vec<ArgMatch>

The calls that are destructive by their arguments, when the command is not destructive whole: a run whose arguments match one of these (CommandSpec::destructive_if) is asked about as a destructive command’s is; the others run at once. An export that only overwrites with clash: "overwrite" says so here.

§private: bool

Its result carries the user’s private data: places (GPS), people (faces, names), absolute file paths. An agent whose grant withholds private data is refused it (the agent socket’s Grant::private); the user’s own runs are never held.

§args: Value

Its arguments: a JSON Schema (CommandSpec::schema), or a free description (an example, a text); null when it takes none. A schema (an object of schema keywords naming a type, see egui_pop_core::debug::is_schema) is enforced: a run whose arguments do not match is refused before its handler, whoever asks it (command.refused, by: "pop.command.args"). A free description checks nothing.

§icon: Option<String>

Its icon’s name (save, phosphor:export, my-plugin:crop): every surface running the command shows it. Checked against the icon vocabulary when the application resolves its declarations.

§icon_on: Option<String>

The icon shown instead while checked holds (eye-off for a toggle whose icon is the eye).

§menu_note: Option<String>

A note at the end of its menu entries, muted, in the keys’ column (a version, “sessions kept”); its keys, if any, come first.

§opens_link: bool

It opens a page outside the application: its menu entries end with ↗.

Implementations§

Source§

impl CommandSpec

Source

pub fn new(id: CommandId, title: &str, category: &str) -> Self

Source

pub fn icon(self, name: &str) -> Self

Its icon, by name: egui-pop’s (save), a Phosphor glyph’s (phosphor:export) or a registered one (my-plugin:crop). Declared once, shown by every surface running the command.

Source

pub fn icon_on(self, name: &str) -> Self

The icon shown while its checked clause holds, by name.

Source

pub fn menu_note(self, note: &str) -> Self

A note at the end of its menu entries (CommandSpec::menu_note).

Its menu entries end with ↗: it opens a page outside the application (CommandSpec::opens_link).

Source

pub fn icon_for(&self, checked: bool) -> Option<&str>

The icon’s name to show: icon_on while checked (when declared), else icon.

Source

pub fn when(self, when: &str) -> Self

Source

pub fn checked(self, clause: &str) -> Self

Ticks its menu entries when the clause holds.

Source

pub fn description(self, text: &str) -> Self

Source

pub fn key(self, keys: &str) -> Self

Adds a default global key binding (a text input keeps plain keys, see keymap::Typing).

Source

pub fn key_with(self, keys: &str, options: BindOptions) -> Self

Adds a default key binding listening as options say: on a surface, while typing, through modals.

Source

pub fn menu(self, menu: MenuId, group: &str, order: i32) -> Self

Adds a menu entry.

Source

pub fn hidden(self) -> Self

Kept out of the palette.

Source

pub fn no_agent(self) -> Self

Kept away from agents.

Source

pub fn read_only(self) -> Self

It only reads: running it changes nothing in the application (no value, file, window or state of any kind). Say it only when true: a read-only debug bridge runs these and refuses the others.

Source

pub fn destructive(self) -> Self

It destroys or discards what cannot easily be had back (CommandSpec::destructive): an agent’s run waits for the user’s confirmation.

Source

pub fn destructive_if(self, arg: &str, value: Json) -> Self

A call whose argument arg equals value is destructive (CommandSpec::destructive_if): an agent’s run with it waits for the user’s confirmation, other runs do not. arg is a top-level argument’s name, or a JSON Pointer (/options/clash). Several rules: any one matching makes the call destructive. CommandSpec::destructive still makes every call destructive.

Source

pub fn is_destructive(&self, args: &Json) -> bool

Whether a call with args is destructive: the command is (CommandSpec::destructive), or its arguments match one of CommandSpec::destructive_if.

Source

pub fn private(self) -> Self

Its result carries private data (CommandSpec::private): an agent whose grant withholds private data is refused it. A command whose result only partly is private may instead leave the private parts out for such an agent (the agent socket’s grants::reads_private).

Source

pub fn args(self, args: Json) -> Self

Describes the arguments (CommandSpec::args): a JSON Schema is enforced, a free description (an example) only shown.

Source

pub fn schema(self, schema: Json) -> Self

Its arguments’ JSON Schema, enforced before every run: arguments that do not match are refused before the handler runs (command.refused, by: "pop.command.args"). The checked subset is egui_pop_core::schema’s (types, required, enum, ranges, lengths, items, additionalProperties, combinators). null arguments are checked as {} when the schema is an object’s. The same as CommandSpec::args, said for what it is.

Trait Implementations§

Source§

impl Clone for CommandSpec

Source§

fn clone(&self) -> CommandSpec

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for CommandSpec

Source§

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

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

impl PartialEq for CommandSpec

Source§

fn eq(&self, other: &CommandSpec) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for CommandSpec

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

impl StructuralPartialEq for CommandSpec

Auto Trait Implementations§

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