Struct wayland_commons::user_data::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: Any + 'static, F: FnOnce() -> T>(&self, f: F)
pub fn set<T: Any + 'static, F: FnOnce() -> T>(&self, f: F)
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: Any + Send + Sync + 'static, F: FnOnce() -> T>(
&self,
f: F
)
pub fn set_threadsafe<T: Any + Send + Sync + 'static, F: FnOnce() -> T>(
&self,
f: F
)
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: 'static>(&self) -> Option<&T>
pub fn get<T: 'static>(&self) -> Option<&T>
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