[−][src]Struct druid::Command
An arbitrary command.
A Command
consists of a Selector
, that indicates what the command is,
and an optional argument, that can be used to pass arbitrary data.
One-shot and reusable Commands
Commands come in two varieties, 'reusable' and 'one-shot'.
Regular commands are created with Command::new
, and their argument
objects may be accessed repeatedly, via Command::get_object
.
One-shot commands are intended for cases where an object should only be used once; an example would be if you have some resource that cannot be cloned, and you wish to send it to another widget.
Examples
use druid::{Command, Selector}; let selector = Selector::new("process_rows"); let rows = vec![1, 3, 10, 12]; let command = Command::new(selector, rows); assert_eq!(command.get_object(), Ok(&vec![1, 3, 10, 12]));
Fields
selector: Selector
The command's Selector
.
Methods
impl Command
[src]
pub fn new(selector: Selector, arg: impl Any) -> Self
[src]
Create a new Command
with an argument. If you do not need
an argument, Selector
implements Into<Command>
.
pub fn one_shot(selector: Selector, arg: impl Any) -> Self
[src]
Create a new 'one-shot' Command
.
Unlike those created with Command::new
, one-shot commands cannot
be reused; their argument is consumed when it is accessed, via
take_object
.
pub fn get_object<T: Any>(&self) -> Result<&T, ArgumentError>
[src]
Return a reference to this Command
's object, if it has one.
This only works for 'reusable' commands; it does not work for commands
created with one_shot
.
pub fn take_object<T: Any>(&self) -> Result<Box<T>, ArgumentError>
[src]
Attempt to take the object of a one-shot
command.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Command
impl !Send for Command
impl !Sync for Command
impl Unpin for Command
impl !UnwindSafe for Command
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> RoundFrom<T> for T
fn round_from(x: T) -> T
impl<T, U> RoundInto<U> for T where
U: RoundFrom<T>,
U: RoundFrom<T>,
fn round_into(self) -> U
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,