[−][src]Struct druid::Command
An arbitrary command.
A Command
consists of a Selector
, that indicates what the command is
and what type of payload it carries, as well as the actual payload.
If the payload can't or shouldn't be cloned,
wrapping it with SingleUse
allows you to take
the payload.
The SingleUse
docs give an example on how to do this.
Generic payloads can be achieved with Selector<Box<dyn Any>>
.
In this case it could make sense to use utility functions to construct
such commands in order to maintain as much static typing as possible.
The EventCtx::new_window
method is an example of this.
Examples
use druid::{Command, Selector, Target}; let selector = Selector::new("process_rows"); let rows = vec![1, 3, 10, 12]; let command = Command::new(selector, rows, Target::Auto); assert_eq!(command.get(selector), Some(&vec![1, 3, 10, 12]));
Implementations
impl Command
[src]
pub fn new<T: Any>(
selector: Selector<T>,
payload: T,
target: impl Into<Target>
) -> Self
[src]
selector: Selector<T>,
payload: T,
target: impl Into<Target>
) -> Self
Create a new Command
with a payload and a Target
.
Selector::with
can be used to create Command
s more conveniently.
If you do not need a payload, Selector
implements Into<Command>
.
pub fn to(self, target: impl Into<Target>) -> Self
[src]
Set the Command
's Target
.
Command::target
can be used to get the current Target
.
pub fn target(&self) -> Target
[src]
Returns the Command
's Target
.
Command::to
can be used to change the Target
.
pub fn is<T>(&self, selector: Selector<T>) -> bool
[src]
Returns true
if self
matches this selector
.
pub fn get<T: Any>(&self, selector: Selector<T>) -> Option<&T>
[src]
Returns Some(&T)
(this Command
's payload) if the selector matches.
Returns None
when self.is(selector) == false
.
Alternatively you can check the selector with is
and then use get_unchecked
.
Panics
Panics when the payload has a different type, than what the selector is supposed to carry. This can happen when two selectors with different types but the same key are used.
pub fn get_unchecked<T: Any>(&self, selector: Selector<T>) -> &T
[src]
Returns a reference to this Command
's payload.
If the selector has already been checked with is
, then get_unchecked
can be used safely.
Otherwise you should use get
instead.
Panics
Panics when self.is(selector) == false
.
Panics when the payload has a different type, than what the selector is supposed to carry. This can happen when two selectors with different types but the same key are used.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Command
[src]
impl !Send for Command
[src]
impl !Sync for Command
[src]
impl Unpin for Command
[src]
impl !UnwindSafe for Command
[src]
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,
pub 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
pub fn round_from(x: T) -> T
impl<T, U> RoundInto<U> for T where
U: RoundFrom<T>,
U: RoundFrom<T>,
pub fn round_into(self) -> U
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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>,