pub struct MainThreadData<T>(/* private fields */);
Expand description
Data that can only be accessed from the main thread. Accessors take a MainThreadToken
.
This can be moved freely between threads, but the Drop implementation will panic if it’s dropped from a thread other than the main thread.
Implementations§
Source§impl<T> MainThreadData<T>
impl<T> MainThreadData<T>
Sourcepub fn new(_: MainThreadToken, data: T) -> Self
pub fn new(_: MainThreadToken, data: T) -> Self
Create a new MainThreadData
.
Sourcepub fn get(&self, _: MainThreadToken) -> &T
pub fn get(&self, _: MainThreadToken) -> &T
Get shared access to this data.
Sourcepub fn get_mut(&mut self, _: MainThreadToken) -> &mut T
pub fn get_mut(&mut self, _: MainThreadToken) -> &mut T
Get exclusive access to this data.
Sourcepub fn get_on_main_thread(&self, callback: impl FnOnce(&T) + Send) -> bool
pub fn get_on_main_thread(&self, callback: impl FnOnce(&T) + Send) -> bool
Get shared access to this data in a callback that’s run on the main thread. This method waits for the callback to complete before returning.
If this is called on a thread other than the main thread, it requires the SDL
event loop to run. See SDL_RunOnMainThread
for details.
Returns false if the callback failed to run.
See also run_sync_on_main_thread()
.
Sourcepub fn get_mut_on_main_thread(
&mut self,
callback: impl FnOnce(&mut T) + Send,
) -> bool
pub fn get_mut_on_main_thread( &mut self, callback: impl FnOnce(&mut T) + Send, ) -> bool
Get exclusive access to this data in a callback that’s run on the main thread. This method waits for the callback to complete before returning.
If this is called on a thread other than the main thread, it requires the SDL
event loop to run. See SDL_RunOnMainThread
for details.
Returns false if the callback failed to run.
See also run_sync_on_main_thread()
.