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§
Source§impl 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§
impl !Freeze for UserData
impl !RefUnwindSafe for UserData
impl Unpin for UserData
impl !UnwindSafe for UserData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more