BorrowedQueue

Struct BorrowedQueue 

Source
pub struct BorrowedQueue { /* private fields */ }
Expand description

A borrowed event queue.

This type is a thin wrapper around a wl_event_queue pointer. If the pointer is a null pointer, this object refers to the default libwayland queue.

Queue implements Deref<Target = BorrowedQueue>.

This type can be used to safely interact with foreign queues. It guarantees that the contained pointer is either null or valid. This type can be passed into Connection::wait_for_events to wait for events to arrive on multiple queues in a race-free way.

You can construct a BorrowedQueue by calling

§Example

let lib = Libwayland::open().unwrap();
let con = lib.connect_to_default_display().unwrap();
let queue1 = con.create_queue(c"queue name");
let queue2 = con.create_queue(c"another queue");
let default_queue = con.borrow_default_queue();

con.wait_for_events(&[&queue1, &queue2, &default_queue]).await.unwrap();

Implementations§

Source§

impl BorrowedQueue

Source

pub fn create_watcher(self) -> Result<QueueWatcher>

Creates a QueueWatcher for event-loop integration.

This is a shorthand for calling Connection::create_watcher with a queue list containing exactly this queue.

The BorrowedQueue is dropped when the last clone of the QueueWatcher is dropped.

Source

pub async fn wait_for_events(&self) -> Result<()>

Completes when there are new events in this queue.

When this function returns Ok(()), this queue has an event queued.

This is a shorthand for calling Connection::wait_for_events with a queue list consisting of exactly this queue.

§Example
let lib = Libwayland::open().unwrap();
let con = lib.connect_to_default_display().unwrap();
let queue = con.create_queue(c"queue name");
let display: WlDisplay = queue.display();

let done = Arc::new(AtomicBool::new(false));
let done2 = done.clone();
let sync = display.sync();
proxy::set_event_handler(&sync, WlCallback::on_done(move |_, _| {
    done2.store(true, Release);
}));

while !done.load(Acquire) {
    queue.wait_for_events().await.unwrap();
    queue.dispatch_pending().unwrap();
}
Examples found in repository?
examples/async-wait/main.rs (line 18)
10async fn main() {
11    let lib = Libwayland::open().unwrap();
12    let con = lib.connect_to_default_display().unwrap();
13    let queue = con.create_local_queue(c"async-wait");
14
15    create_sync(&queue, 1);
16
17    loop {
18        queue.wait_for_events().await.unwrap();
19        queue.dispatch_pending().unwrap();
20    }
21}
Source

pub fn wl_event_queue(&self) -> Option<NonNull<wl_event_queue>>

Returns the wl_event_queue representing this queue.

This function returns None if and only if this queue is the default queue of the connection.

The returned pointer, if any, remains valid as long as this object exists.

§Example
let lib = Libwayland::open().unwrap();
let con = lib.connect_to_default_display().unwrap();
let queue = con.create_queue(c"queue name");
let default_queue = con.borrow_default_queue();

assert_eq!((**queue).wl_event_queue(), Some(queue.wl_event_queue()));
assert_eq!(default_queue.wl_event_queue(), None);

Auto Trait Implementations§

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> 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, 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.