Struct MainThreadData

Source
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>

Source

pub fn new(_: MainThreadToken, data: T) -> Self

Create a new MainThreadData.

Source

pub fn get(&self, _: MainThreadToken) -> &T

Get shared access to this data.

Source

pub fn get_mut(&mut self, _: MainThreadToken) -> &mut T

Get exclusive access to this data.

Source

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().

Source

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().

Trait Implementations§

Source§

impl<T> Drop for MainThreadData<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> Send for MainThreadData<T>

Source§

impl<T> Sync for MainThreadData<T>

Auto Trait Implementations§

§

impl<T> Freeze for MainThreadData<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for MainThreadData<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for MainThreadData<T>
where T: Unpin,

§

impl<T> UnwindSafe for MainThreadData<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.