pub trait DelegateDispatch<I: Proxy, D: Dispatch<I, UserData = <Self as DelegateDispatchBase<I>>::UserData>>: Sized + DelegateDispatchBase<I> {
    fn event(
        data: &mut D,
        proxy: &I,
        event: I::Event,
        udata: &Self::UserData,
        connhandle: &mut ConnectionHandle<'_>,
        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, DelegateDispatchBase, Dispatch};

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

// Now implement DelegateDispatchBase.
impl DelegateDispatchBase<wl_registry::WlRegistry> for DelegateToMe {
    /// The type of user data associated with the delegation of events from a registry is defined here.
    ///
    /// If you don't need user data, the unit type, `()`, may be used.
    type UserData = ();
}

// Now implement DelegateDispatch.
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, UserData = Self::UserData>,
    // 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: &Self::UserData,
        _connhandle: &mut wayland_client::ConnectionHandle,
        _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