Struct glib::MainContext
source · #[repr(transparent)]pub struct MainContext { /* private fields */ }
Implementations§
source§impl MainContext
impl MainContext
pub fn new() -> MainContext
pub fn with_flags(flags: MainContextFlags) -> MainContext
v2_72
only.pub fn dispatch(&self)
pub fn is_owner(&self) -> bool
pub fn iteration(&self, may_block: bool) -> bool
pub fn pending(&self) -> bool
pub fn wakeup(&self)
pub fn default() -> MainContext
pub fn thread_default() -> Option<MainContext>
pub fn ref_thread_default() -> MainContext
source§impl MainContext
impl MainContext
pub fn prepare(&self) -> (bool, i32)
pub fn find_source_by_id(&self, source_id: &SourceId) -> Option<Source>
sourcepub fn invoke<F>(&self, func: F)where
F: FnOnce() + Send + 'static,
pub fn invoke<F>(&self, func: F)where F: FnOnce() + Send + 'static,
Invokes func
on the main context.
If the current thread is the owner of the main context or the main context currently has no
owner then func
will be called directly from inside this function. If this behaviour is
not desired and func
should always be called asynchronously then use MainContext::spawn
glib::idle_add
instead.
sourcepub fn invoke_with_priority<F>(&self, priority: Priority, func: F)where
F: FnOnce() + Send + 'static,
pub fn invoke_with_priority<F>(&self, priority: Priority, func: F)where F: FnOnce() + Send + 'static,
Invokes func
on the main context with the given priority.
If the current thread is the owner of the main context or the main context currently has no
owner then func
will be called directly from inside this function. If this behaviour is
not desired and func
should always be called asynchronously then use MainContext::spawn
glib::idle_add
instead.
sourcepub fn invoke_local<F>(&self, func: F)where
F: FnOnce() + 'static,
pub fn invoke_local<F>(&self, func: F)where F: FnOnce() + 'static,
Invokes func
on the main context.
Different to invoke()
, this does not require func
to be
Send
but can only be called from the thread that owns the main context.
This function panics if called from a different thread than the one that owns the main context.
Note that this effectively means that func
is called directly from inside this function
or otherwise panics immediately. If this behaviour is not desired and func
should always
be called asynchronously then use MainContext::spawn_local
glib::idle_add_local
instead.
sourcepub fn invoke_local_with_priority<F>(&self, _priority: Priority, func: F)where
F: FnOnce() + 'static,
pub fn invoke_local_with_priority<F>(&self, _priority: Priority, func: F)where F: FnOnce() + 'static,
Invokes func
on the main context with the given priority.
Different to invoke_with_priority()
, this does not require func
to be
Send
but can only be called from the thread that owns the main context.
This function panics if called from a different thread than the one that owns the main context.
Note that this effectively means that func
is called directly from inside this function
or otherwise panics immediately. If this behaviour is not desired and func
should always
be called asynchronously then use MainContext::spawn_local
glib::idle_add_local
instead.
sourcepub fn with_thread_default<R, F>(&self, func: F) -> Result<R, BoolError>where
F: FnOnce() -> R + Sized,
pub fn with_thread_default<R, F>(&self, func: F) -> Result<R, BoolError>where F: FnOnce() -> R + Sized,
Call closure with the main context configured as the thread default one.
The thread default main context is changed in a panic-safe manner before calling func
and
released again afterwards regardless of whether closure panicked or not.
This will fail if the main context is owned already by another thread.
sourcepub fn acquire(&self) -> Result<MainContextAcquireGuard<'_>, BoolError>
pub fn acquire(&self) -> Result<MainContextAcquireGuard<'_>, BoolError>
Acquire ownership of the main context.
Ownership will automatically be released again once the returned acquire guard is dropped.
This will fail if the main context is owned already by another thread.
source§impl MainContext
impl MainContext
sourcepub fn channel<T>(priority: Priority) -> (Sender<T>, Receiver<T>)
pub fn channel<T>(priority: Priority) -> (Sender<T>, Receiver<T>)
Creates a channel for a main context.
The Receiver
has to be attached to a main context at a later time, together with a
closure that will be called for every item sent to a Sender
.
The Sender
can be cloned and both the Sender
and Receiver
can be sent to different
threads as long as the item type implements the Send
trait.
When the last Sender
is dropped the channel is removed from the main context. If the
Receiver
is dropped and not attached to a main context all sending to the Sender
will fail.
The returned Sender
behaves the same as std::sync::mpsc::Sender
.
sourcepub fn sync_channel<T>(
priority: Priority,
bound: usize
) -> (SyncSender<T>, Receiver<T>)
pub fn sync_channel<T>( priority: Priority, bound: usize ) -> (SyncSender<T>, Receiver<T>)
Creates a synchronous channel for a main context with a given bound on the capacity of the channel.
The Receiver
has to be attached to a main context at a later time, together with a
closure that will be called for every item sent to a SyncSender
.
The SyncSender
can be cloned and both the SyncSender
and Receiver
can be sent to different
threads as long as the item type implements the Send
trait.
When the last SyncSender
is dropped the channel is removed from the main context. If the
Receiver
is dropped and not attached to a main context all sending to the SyncSender
will fail.
The returned SyncSender
behaves the same as std::sync::mpsc::SyncSender
.
source§impl MainContext
impl MainContext
sourcepub fn spawn<F: Future<Output = ()> + Send + 'static>(&self, f: F) -> SourceId
pub fn spawn<F: Future<Output = ()> + Send + 'static>(&self, f: F) -> SourceId
Spawn a new infallible Future
on the main context.
This can be called from any thread and will execute the future from the thread
where main context is running, e.g. via a MainLoop
.
sourcepub fn spawn_local<F: Future<Output = ()> + 'static>(&self, f: F) -> SourceId
pub fn spawn_local<F: Future<Output = ()> + 'static>(&self, f: F) -> SourceId
Spawn a new infallible Future
on the main context.
The given Future
does not have to be Send
.
This can be called only from the thread where the main context is running, e.g.
from any other Future
that is executed on this main context, or after calling
with_thread_default
or acquire
on the main context.
sourcepub fn spawn_with_priority<F: Future<Output = ()> + Send + 'static>(
&self,
priority: Priority,
f: F
) -> SourceId
pub fn spawn_with_priority<F: Future<Output = ()> + Send + 'static>( &self, priority: Priority, f: F ) -> SourceId
Spawn a new infallible Future
on the main context, with a non-default priority.
This can be called from any thread and will execute the future from the thread
where main context is running, e.g. via a MainLoop
.
sourcepub fn spawn_local_with_priority<F: Future<Output = ()> + 'static>(
&self,
priority: Priority,
f: F
) -> SourceId
pub fn spawn_local_with_priority<F: Future<Output = ()> + 'static>( &self, priority: Priority, f: F ) -> SourceId
Spawn a new infallible Future
on the main context, with a non-default priority.
The given Future
does not have to be Send
.
This can be called only from the thread where the main context is running, e.g.
from any other Future
that is executed on this main context, or after calling
with_thread_default
or acquire
on the main context.
sourcepub fn block_on<F: Future>(&self, f: F) -> F::Output
pub fn block_on<F: Future>(&self, f: F) -> F::Output
Runs a new, infallible Future
on the main context and block until it finished, returning
the result of the Future
.
The given Future
does not have to be Send
or 'static
.
This must only be called if no MainLoop
or anything else is running on this specific main
context.
Trait Implementations§
source§impl Clone for MainContext
impl Clone for MainContext
source§impl Debug for MainContext
impl Debug for MainContext
source§impl Default for MainContext
impl Default for MainContext
source§impl Hash for MainContext
impl Hash for MainContext
source§impl LocalSpawn for MainContext
impl LocalSpawn for MainContext
source§fn spawn_local_obj(
&self,
f: LocalFutureObj<'static, ()>
) -> Result<(), SpawnError>
fn spawn_local_obj( &self, f: LocalFutureObj<'static, ()> ) -> Result<(), SpawnError>
source§fn status_local(&self) -> Result<(), SpawnError>
fn status_local(&self) -> Result<(), SpawnError>
source§impl Ord for MainContext
impl Ord for MainContext
source§fn cmp(&self, other: &MainContext) -> Ordering
fn cmp(&self, other: &MainContext) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq<MainContext> for MainContext
impl PartialEq<MainContext> for MainContext
source§fn eq(&self, other: &MainContext) -> bool
fn eq(&self, other: &MainContext) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<MainContext> for MainContext
impl PartialOrd<MainContext> for MainContext
source§fn partial_cmp(&self, other: &MainContext) -> Option<Ordering>
fn partial_cmp(&self, other: &MainContext) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Spawn for MainContext
impl Spawn for MainContext
source§impl StaticType for MainContext
impl StaticType for MainContext
source§fn static_type() -> Type
fn static_type() -> Type
Self
.impl Eq for MainContext
impl Send for MainContext
impl StructuralEq for MainContext
impl StructuralPartialEq for MainContext
impl Sync for MainContext
Auto Trait Implementations§
Blanket Implementations§
source§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
source§impl<Sp> LocalSpawnExt for Spwhere
Sp: LocalSpawn + ?Sized,
impl<Sp> LocalSpawnExt for Spwhere Sp: LocalSpawn + ?Sized,
source§fn spawn_local<Fut>(&self, future: Fut) -> Result<(), SpawnError>where
Fut: Future<Output = ()> + 'static,
fn spawn_local<Fut>(&self, future: Fut) -> Result<(), SpawnError>where Fut: Future<Output = ()> + 'static,
()
to
completion. Read moresource§impl<T> StaticTypeExt for Twhere
T: StaticType,
impl<T> StaticTypeExt for Twhere T: StaticType,
source§fn ensure_type()
fn ensure_type()
source§impl<T> ToClosureReturnValue for Twhere
T: ToValue,
impl<T> ToClosureReturnValue for Twhere T: ToValue,
fn to_closure_return_value(&self) -> Option<Value>
source§impl<T> ToSendValue for Twhere
T: Send + ToValue + ?Sized,
impl<T> ToSendValue for Twhere T: Send + ToValue + ?Sized,
source§fn to_send_value(&self) -> SendValue
fn to_send_value(&self) -> SendValue
SendValue
clone of self
.