pub struct MainThreadToken(/* private fields */);
Expand description
Zero sized token that can only exist on the main thread.
Call MainThreadToken::get()
or MainThreadToken::assert()
to get one.
Implementations§
Source§impl MainThreadToken
impl MainThreadToken
Sourcepub fn get() -> Option<Self>
pub fn get() -> Option<Self>
Get Some(MainThreadToken)
if called on the main thread, or None
otherwise.
Returns None
if MainThreadToken
hasn’t been inited.
On targets that don’t support threads, this will always succeed if MainThreadToken
has been inited.
See also MainThreadToken::assert()
Sourcepub fn assert() -> Self
pub fn assert() -> Self
Get MainThreadToken
if called on the main thread, or panic otherwise.
Panics if MainThreadToken
hasn’t been inited.
On targets that don’t support threads, this will always succeed if MainThreadToken
has been inited.
See also MainThreadToken::get()
Sourcepub unsafe fn init()
pub unsafe fn init()
Init and declare the current thread as the main thread.
This doesn’t change what’s the actual main thread, and it’s UB to call this on
any thread other than the main thread. MainThreadToken::get()
and
MainThreadToken::assert()
will fail on any thread including the main thread
before this function is called.
The main
and app_init
macros will call this for you.
§Safety
It’s undefined behaviour to call this on any thread other than the main thread. On targets that don’t support threads, this is always safe.
Trait Implementations§
Source§impl Clone for MainThreadToken
impl Clone for MainThreadToken
Source§fn clone(&self) -> MainThreadToken
fn clone(&self) -> MainThreadToken
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more