[][src]Struct druid::SingleUse

pub struct SingleUse<T>(_);

A wrapper type for Command payloads that should only be used once.

This is useful if you have some resource that cannot be cloned, and you wish to send it to another widget.

Examples

use druid::{Command, Selector, SingleUse, Target};

struct CantClone(u8);

let selector = Selector::new("use-once");
let num = CantClone(42);
let command = Command::new(selector, SingleUse::new(num), Target::Auto);

let payload: &SingleUse<CantClone> = command.get_unchecked(selector);
if let Some(num) = payload.take() {
    // now you own the data
    assert_eq!(num.0, 42);
}

// subsequent calls will return `None`
assert!(payload.take().is_none());

Implementations

impl<T: Any> SingleUse<T>[src]

pub fn new(data: T) -> Self[src]

Create a new single-use payload.

pub fn take(&self) -> Option<T>[src]

Takes the value, leaving a None in its place.

Auto Trait Implementations

impl<T> RefUnwindSafe for SingleUse<T>[src]

impl<T> Send for SingleUse<T> where
    T: Send
[src]

impl<T> Sync for SingleUse<T> where
    T: Send
[src]

impl<T> Unpin for SingleUse<T> where
    T: Unpin
[src]

impl<T> UnwindSafe for SingleUse<T>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> RoundFrom<T> for T

impl<T, U> RoundInto<U> for T where
    U: RoundFrom<T>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.