Struct Source

Source
pub struct Source<T> { /* private fields */ }
Expand description

A binding to the GSource underlying type.

Implementations§

Source§

impl<T: SourceFuncs> Source<T>

Source

pub fn new(t: T) -> Source<T>

Creates a new GSource structure.

The source will not initially be associated with any MainContext and must be added to one with attach before it will be executed.

Source

pub fn get_ref(&self) -> &T

Acquires an underlying reference to the data contained within this Source.

Source

pub fn attach(&self, context: &MainContext)

Adds a Source to a context so that it will be executed within that context.

Source

pub fn destroy(&self)

Removes a source from its MainContext, if any, and mark it as destroyed.

The source cannot be subsequently added to another context. It is safe to call this on sources which have already been removed from their context.

Source

pub fn set_priority(&self, priority: i32)

Sets the priority of a source.

While the main loop is being run, a source will be dispatched if it is ready to be dispatched and no sources at a higher (numerically smaller) priority are ready to be dispatched.

A child source always has the same priority as its parent. It is not permitted to change the priority of a source once it has been added as a child of another source.

Source

pub fn priority(&self) -> i32

Gets the priority of a source.

Source

pub fn set_can_recurse(&self, can_recurse: bool)

Sets whether a source can be called recursively.

If can_recurse is true, then while the source is being dispatched then this source will be processed normally. Otherwise, all processing of this source is blocked until the dispatch function returns.

Source

pub fn can_recurse(&self) -> bool

Checks whether a source is allowed to be called recursively.

Source

pub fn get_id(&self) -> u32

Returns the numeric ID for a particular source.

The ID of a source is a positive integer which is unique within a particular main loop context.

Source

pub fn context(&self) -> Option<MainContext>

Gets the MainContext with which the source is associated.

Source

pub fn set_callback<F>(&self, f: F)
where F: FnMut(T::CallbackArg) -> bool + 'static,

Sets the callback function for a source. The callback for a source is called from the source’s dispatch function.

Source

pub fn set_ready_time(&self, ready_time: Option<Instant>)

Sets a Source to be dispatched when the given monotonic time is reached (or passed). If the monotonic time is in the past (as it always will be if ready_time is the current time) then the source will be dispatched immediately.

If ready_time is None then the source is never woken up on the basis of the passage of time.

Dispatching the source does not reset the ready time. You should do so yourself, from the source dispatch function.

Note that if you have a pair of sources where the ready time of one suggests that it will be delivered first but the priority for the other suggests that it would be delivered first, and the ready time for both sources is reached during the same main context iteration then the order of dispatch is undefined.

This API is only intended to be used by implementations of Source. Do not call this API on a Source that you did not create.

Source

pub fn unix_add_fd(&self, fd: i32, events: &IoCondition) -> UnixToken

Monitors fd for the IO events in events.

The token returned by this function can be used to remove or modify the monitoring of the fd using unix_remove_fd or unix_modify_fd.

It is not necessary to remove the fd before destroying the source; it will be cleaned up automatically.

This API is only intended to be used by implementations of Source. Do not call this API on a Source that you did not create.

As the name suggests, this function is not available on Windows.

Source

pub unsafe fn unix_modify_fd(&self, token: &UnixToken, events: &IoCondition)

Updates the event mask to watch for the fd identified by tag .

token is the token returned from unix_add_fd

If you want to remove a fd, don’t set its event mask to zero. Instead, call remove_unix_fd

This API is only intended to be used by implementations of Source. Do not call this API on a Source that you did not create.

As the name suggests, this function is not available on Windows.

§Unsafety

This function can only be called with tokens that were returned from this source’s unix_add_fd implementation and haven’t been removed yet.

Source

pub unsafe fn unix_remove_fd(&self, token: &UnixToken)

Reverses the effect of a previous call to unix_add_fd.

You only need to call this if you want to remove an fd from being watched while keeping the same source around. In the normal case you will just want to destroy the source.

This API is only intended to be used by implementations of Source. Do not call this API on a Source that you did not create.

As the name suggests, this function is not available on Windows.

§Unsafety

This function can only be called with tokens that were returned from this source’s unix_add_fd implementation and haven’t been removed yet.

Source

pub unsafe fn unix_query_fd(&self, token: &UnixToken) -> IoCondition

Queries the events reported for the fd corresponding to token on source during the last poll.

The return value of this function is only defined when the function is called from the check or dispatch functions for source.

This API is only intended to be used by implementations of Source. Do not call this API on a Source that you did not create.

As the name suggests, this function is not available on Windows.

§Unsafety

This function can only be called with tokens that were returned from this source’s unix_add_fd implementation and haven’t been removed yet.

Trait Implementations§

Source§

impl<T> Clone for Source<T>

Source§

fn clone(&self) -> Source<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Drop for Source<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Source<T>

§

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

§

impl<T> !Send for Source<T>

§

impl<T> !Sync for Source<T>

§

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

§

impl<T> UnwindSafe for Source<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.