Struct wayland_client::UserData
source · [−]pub struct UserData { /* private fields */ }
Expand description
A wrapper for user data, able to store any type, and correctly handling access from a wrong thread
Implementations
sourceimpl UserData
impl UserData
sourcepub fn set<T, F>(&self, f: F) where
T: 'static + Any,
F: FnOnce() -> T,
pub fn set<T, F>(&self, f: F) where
T: 'static + Any,
F: FnOnce() -> T,
Sets the UserData to a given value
The provided closure is called to init the UserData, does nothing is the UserData had already been set.
sourcepub fn set_threadsafe<T, F>(&self, f: F) where
T: 'static + Any + Send + Sync,
F: FnOnce() -> T,
pub fn set_threadsafe<T, F>(&self, f: F) where
T: 'static + Any + Send + Sync,
F: FnOnce() -> T,
Sets the UserData to a given threadsafe value
The provided closure is called to init the UserData, does nothing is the UserData had already been set.
sourcepub fn get<T>(&self) -> Option<&T> where
T: 'static,
pub fn get<T>(&self) -> Option<&T> where
T: 'static,
Attempt to access the wrapped user data
Will return None
if either:
- The requested type
T
does not match the type used for construction - This
UserData
has been created using the non-threadsafe variant and access is attempted from an other thread than the one it was created on
Trait Implementations
impl Send for UserData
impl Sync for UserData
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
sourcefn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more