Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: let delegate_noop can handle constGeneric #679

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions wayland-client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- Implement `AsFd` for `Connection` and `EventQueue` so they can easily be used in a
`calloop` source.
- Make `delegate_noop` usable for constGeneric type.

## 0.31.0 -- 2023-09-02

Expand Down
29 changes: 23 additions & 6 deletions wayland-client/src/event_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@ impl ObjectData for TemporaryData {
/// ```
#[macro_export]
macro_rules! delegate_dispatch {
($(@< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from:ty : [$interface: ty: $udata: ty] => $dispatch_to: ty) => {
impl$(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, $udata> for $dispatch_from {
($(@< $( $($lt:ident )+ $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from:ty : [$interface: ty: $udata: ty] => $dispatch_to: ty) => {
impl$(< $( $($lt )+ $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, $udata> for $dispatch_from {
fn event(
state: &mut Self,
proxy: &$interface,
Expand Down Expand Up @@ -831,13 +831,28 @@ macro_rules! delegate_dispatch {
///
/// // This interface should not emit events:
/// delegate_noop!(ExampleApp: wl_subcompositor::WlSubcompositor);
///
/// // Also you can do it with generic type, for example
/// struct ExampleAppGeneric<const X: usize>;
/// delegate_noop!(@<const X: usize> ExampleAppGeneric<X>: ignore wl_data_offer::WlDataOffer);
/// delegate_noop!(@<const X: usize> ExampleAppGeneric<X>: wl_subcompositor::WlSubcompositor);
///
/// // @ is to start with generic, and for base generic type looks like below.
/// trait E {
/// // add code here
/// }
/// struct ExampleAppGeneric2<T: E> {
/// a: T
/// }
/// delegate_noop!(@<T: E> ExampleAppGeneric2<T>: wl_data_offer::WlDataOffer);
/// delegate_noop!(@<T: E> ExampleAppGeneric2<T>: ignore wl_subcompositor::WlSubcompositor);
/// ```
///
/// This last example will execute `unreachable!()` if the interface emits any events.
#[macro_export]
macro_rules! delegate_noop {
($(@< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from: ty : $interface: ty) => {
impl$(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, ()> for $dispatch_from {
($(@< $( $($lt:ident )+ $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from: ty : $interface: ty) => {
impl$(< $( $($lt )+ $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, ()> for $dispatch_from {
fn event(
_: &mut Self,
_: &$interface,
Expand All @@ -851,8 +866,9 @@ macro_rules! delegate_noop {
}
};

($(@< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from: ty : ignore $interface: ty) => {
impl$(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, ()> for $dispatch_from {

($(@< $( $($lt:ident )+ $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from: ty : ignore $interface: ty) => {
impl$(< $( $($lt )+ $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, ()> for $dispatch_from {
fn event(
_: &mut Self,
_: &$interface,
Expand All @@ -864,4 +880,5 @@ macro_rules! delegate_noop {
}
}
};

}
1 change: 1 addition & 0 deletions wayland-server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Updated wayland-backend to 0.3
- Use `BorrowedFd<'_>` arguments instead of `RawFd`
- `Resource::destroyed` now passes the resource type instead of the `ObjectId`.
- Make `delegate_dispatch` usable for constGeneric type.

#### Additions

Expand Down
9 changes: 7 additions & 2 deletions wayland-server/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,15 @@ impl<I: Resource + 'static, U: Send + Sync + 'static, D: Dispatch<I, U> + 'stati
/// }
/// }
/// ```
/// This macro_rules also support to be used with generic type, it will be similiar with client one
/// like
/// ```ignore
/// delegate_dispatch!(@<const X : usize> ExampleApp<X>: [wl_output::WlOutput: MyUserData] => DelegateToMe);
/// ```
#[macro_export]
macro_rules! delegate_dispatch {
($(@< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from:ty : [$interface: ty: $udata: ty] => $dispatch_to: ty) => {
impl$(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, $udata> for $dispatch_from {
($(@< $( $($lt:ident )+ $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? $dispatch_from:ty : [$interface: ty: $udata: ty] => $dispatch_to: ty) => {
impl$(< $( $($lt )+ $( : $clt $(+ $dlt )* )? ),+ >)? $crate::Dispatch<$interface, $udata> for $dispatch_from {
fn request(
state: &mut Self,
client: &$crate::Client,
Expand Down