pub trait DelegateDispatch<I: Proxy, U, D: Dispatch<I, U>> {
    fn event(
        data: &mut D,
        proxy: &I,
        event: I::Event,
        udata: &U,
        conn: &Connection,
        qhandle: &QueueHandle<D>
    ); fn event_created_child(
        opcode: u16,
        _qhandle: &QueueHandle<D>
    ) -> Arc<dyn ObjectData> { ... } }
Expand description

A trait which defines a delegate type to handle some type of proxy.

This trait is useful for building modular handlers of proxies.

Usage

To explain the trait, let’s implement a delegate for handling the events from WlRegistry.

use wayland_client::{protocol::wl_registry, DelegateDispatch, Dispatch};

/// The type we want to delegate to
struct DelegateToMe;

// Now implement DelegateDispatch.
// The second parameter specifies which type of user data is associated with the registry.
impl<D> DelegateDispatch<wl_registry::WlRegistry, (), D> for DelegateToMe
where
    // `D` is the type which has delegated to this type.
    D: Dispatch<wl_registry::WlRegistry, ()>,
    // If your delegate type has some internal state, it'll need to access it, and you can
    // require it via an AsMut<_> implementation for example
    D: AsMut<DelegateToMe>,
{
    fn event(
        data: &mut D,
        _proxy: &wl_registry::WlRegistry,
        _event: wl_registry::Event,
        _udata: &(),
        _conn: &wayland_client::Connection,
        _qhandle: &wayland_client::QueueHandle<D>,
    ) {
        // Here the delegate may handle incoming events as it pleases.

        // For example, it retrives its state and does some processing with it
        let me: &mut DelegateToMe = data.as_mut();
        // do something with `me` ...
    }
}

Required Methods

Called when an event from the server is processed.

The implementation of this function may vary depending on protocol requirements. Typically the client will respond to the server by sending requests to the proxy.

Provided Methods

Method used to initialize the user-data of objects created by events

If the interface does not have any such event, you can ignore it. If not, the event_created_child! macro is provided for overriding it.

Implementors