macro_rules! delegate_dispatch { ($(@< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from:ty : [$interface: ty: $udata: ty] => $dispatch_to: ty) => { ... }; }
Expand description
A helper macro which delegates a set of Dispatch
implementations for a resource to some other type which
provides a generic Dispatch
implementation.
This macro allows more easily delegating smaller parts of the protocol a compositor may wish to handle in a modular fashion.
ยงUsage
For example, say you want to delegate events for WlOutput
to the DelegateToMe
type from the Dispatch
documentation.
use wayland_server::{delegate_dispatch, protocol::wl_output};
// ExampleApp is the type events will be dispatched to.
/// The application state
struct ExampleApp {
/// The delegate for handling wl_registry events.
delegate: DelegateToMe,
}
// Use delegate_dispatch to implement Dispatch<wl_output::WlOutput, MyUserData> for ExampleApp.
delegate_dispatch!(ExampleApp: [wl_output::WlOutput: MyUserData] => DelegateToMe);
// DelegateToMe requires that ExampleApp implements AsMut<DelegateToMe>, so we provide the trait implementation.
impl AsMut<DelegateToMe> for ExampleApp {
fn as_mut(&mut self) -> &mut DelegateToMe {
&mut self.delegate
}
}