pub trait SourceFuncs: Sized {
type CallbackArg;
// Required methods
fn prepare(&self, source: &Source<Self>) -> (bool, Option<Duration>);
fn check(&self, source: &Source<Self>) -> bool;
fn dispatch(
&self,
source: &Source<Self>,
f: GSourceFunc,
data: gpointer,
) -> bool;
fn g_source_func<F>() -> GSourceFunc
where F: FnMut(Self::CallbackArg) -> bool;
}
Expand description
Trait for the callbacks that will be invoked by the Source
type.
Required Associated Types§
Sourcetype CallbackArg
type CallbackArg
Type passed to the callback in dispatch
.
Required Methods§
Sourcefn prepare(&self, source: &Source<Self>) -> (bool, Option<Duration>)
fn prepare(&self, source: &Source<Self>) -> (bool, Option<Duration>)
Called before all the file descriptors are polled.
If the source can determine that it is ready here (without waiting for
the results of the poll() call) it should return true
. It can also
return a timeout value which should be the maximum timeout which should
be passed to the poll() call.
The actual timeout used will be -1 if all sources returned None
or it
will be the minimum of all the timeout_ values returned which were >= 0.
If prepare returns a timeout and the source also has a ‘ready time’ set
then the nearer of the two will be used.
Sourcefn check(&self, source: &Source<Self>) -> bool
fn check(&self, source: &Source<Self>) -> bool
Called after all the file descriptors are polled.
The source should return true
if it is ready to be dispatched. Note
that some time may have passed since the previous prepare function was
called, so the source should be checked again here.
Sourcefn dispatch(
&self,
source: &Source<Self>,
f: GSourceFunc,
data: gpointer,
) -> bool
fn dispatch( &self, source: &Source<Self>, f: GSourceFunc, data: gpointer, ) -> bool
Called to dispatch the event source, after it has returned true
in
either its prepare
or its check
function.
The dispatch function is passed in a callback function. The dispatch
function should call the callback function. The return value of the
dispatch function should be false
if the source should be removed or
true
to keep it.
Sourcefn g_source_func<F>() -> GSourceFunc
fn g_source_func<F>() -> GSourceFunc
Returns an FFI function pointer to invoke the closure specified.
This is used to implement the set_callback
function.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.