Trait futures_glib::SourceFuncs
[−]
[src]
pub trait SourceFuncs: Sized { type CallbackArg; 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; }
Trait for the callbacks that will be invoked by the Source
type.
Associated Types
type CallbackArg
Type passed to the callback in dispatch
.
Required Methods
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.
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.
fn dispatch(
&self,
source: &Source<Self>,
f: GSourceFunc,
data: gpointer
) -> bool
&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.
fn g_source_func<F>() -> GSourceFunc where
F: FnMut(Self::CallbackArg) -> bool,
F: FnMut(Self::CallbackArg) -> bool,
Returns an FFI function pointer to invoke the closure specified.
This is used to implement the set_callback
function.