Skip to content

Commit

Permalink
Begone delegate macros init
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed Feb 11, 2024
1 parent eb7a57b commit 443cb1f
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 77 deletions.
7 changes: 6 additions & 1 deletion wayland-scanner/src/server_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn generate_objects_for(interface: &Interface) -> TokenStream {
smallvec, ObjectData, ObjectId, InvalidId, WeakHandle,
protocol::{WEnum, Argument, Message, Interface, same_interface}
},
Resource, Dispatch, DisplayHandle, DispatchError, ResourceData, New, Weak,
Resource, Dispatch, DisplayHandle, DispatchError, ResourceData, DelegatedResourceData, New, Weak,
};

#enums
Expand Down Expand Up @@ -132,6 +132,11 @@ fn generate_objects_for(interface: &Interface) -> TokenStream {
self.data.as_ref().and_then(|arc| (&**arc).downcast_ref::<ResourceData<Self, U>>()).map(|data| &data.udata)
}

#[inline]
fn delegated_data<U: 'static, M: 'static>(&self) -> Option<&U> {
self.data.as_ref().and_then(|arc| (&**arc).downcast_ref::<DelegatedResourceData<Self, U, M>>()).map(|data| &data.udata)
}

#[inline]
fn object_data(&self) -> Option<&Arc<dyn std::any::Any + Send + Sync>> {
self.data.as_ref()
Expand Down
60 changes: 50 additions & 10 deletions wayland-scanner/tests/scanner_assets/test-server-code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ pub mod wl_callback {
protocol::{same_interface, Argument, Interface, Message, WEnum},
smallvec, InvalidId, ObjectData, ObjectId, WeakHandle,
},
Dispatch, DispatchError, DisplayHandle, New, Resource, ResourceData, Weak,
DelegatedResourceData, Dispatch, DispatchError, DisplayHandle, New, Resource, ResourceData,
Weak,
};
use std::sync::Arc;
use std::os::unix::io::OwnedFd;
use std::sync::Arc;
#[doc = r" The minimal object version supporting this event"]
pub const EVT_DONE_SINCE: u32 = 1u32;
#[doc = r" The wire opcode for this event"]
Expand Down Expand Up @@ -97,6 +98,13 @@ pub mod wl_callback {
.map(|data| &data.udata)
}
#[inline]
fn delegated_data<U: 'static, M: 'static>(&self) -> Option<&U> {
self.data
.as_ref()
.and_then(|arc| (&**arc).downcast_ref::<DelegatedResourceData<Self, U, M>>())
.map(|data| &data.udata)
}
#[inline]
fn object_data(&self) -> Option<&Arc<dyn std::any::Any + Send + Sync>> {
self.data.as_ref()
}
Expand Down Expand Up @@ -169,10 +177,11 @@ pub mod test_global {
protocol::{same_interface, Argument, Interface, Message, WEnum},
smallvec, InvalidId, ObjectData, ObjectId, WeakHandle,
},
Dispatch, DispatchError, DisplayHandle, New, Resource, ResourceData, Weak,
DelegatedResourceData, Dispatch, DispatchError, DisplayHandle, New, Resource, ResourceData,
Weak,
};
use std::sync::Arc;
use std::os::unix::io::OwnedFd;
use std::sync::Arc;
#[doc = r" The minimal object version supporting this request"]
pub const REQ_MANY_ARGS_SINCE: u32 = 1u32;
#[doc = r" The wire opcode for this request"]
Expand Down Expand Up @@ -359,6 +368,13 @@ pub mod test_global {
.map(|data| &data.udata)
}
#[inline]
fn delegated_data<U: 'static, M: 'static>(&self) -> Option<&U> {
self.data
.as_ref()
.and_then(|arc| (&**arc).downcast_ref::<DelegatedResourceData<Self, U, M>>())
.map(|data| &data.udata)
}
#[inline]
fn object_data(&self) -> Option<&Arc<dyn std::any::Any + Send + Sync>> {
self.data.as_ref()
}
Expand Down Expand Up @@ -774,10 +790,11 @@ pub mod secondary {
protocol::{same_interface, Argument, Interface, Message, WEnum},
smallvec, InvalidId, ObjectData, ObjectId, WeakHandle,
},
Dispatch, DispatchError, DisplayHandle, New, Resource, ResourceData, Weak,
DelegatedResourceData, Dispatch, DispatchError, DisplayHandle, New, Resource, ResourceData,
Weak,
};
use std::sync::Arc;
use std::os::unix::io::OwnedFd;
use std::sync::Arc;
#[doc = r" The minimal object version supporting this request"]
pub const REQ_DESTROY_SINCE: u32 = 2u32;
#[doc = r" The wire opcode for this request"]
Expand Down Expand Up @@ -865,6 +882,13 @@ pub mod secondary {
.map(|data| &data.udata)
}
#[inline]
fn delegated_data<U: 'static, M: 'static>(&self) -> Option<&U> {
self.data
.as_ref()
.and_then(|arc| (&**arc).downcast_ref::<DelegatedResourceData<Self, U, M>>())
.map(|data| &data.udata)
}
#[inline]
fn object_data(&self) -> Option<&Arc<dyn std::any::Any + Send + Sync>> {
self.data.as_ref()
}
Expand Down Expand Up @@ -933,10 +957,11 @@ pub mod tertiary {
protocol::{same_interface, Argument, Interface, Message, WEnum},
smallvec, InvalidId, ObjectData, ObjectId, WeakHandle,
},
Dispatch, DispatchError, DisplayHandle, New, Resource, ResourceData, Weak,
DelegatedResourceData, Dispatch, DispatchError, DisplayHandle, New, Resource, ResourceData,
Weak,
};
use std::sync::Arc;
use std::os::unix::io::OwnedFd;
use std::sync::Arc;
#[doc = r" The minimal object version supporting this request"]
pub const REQ_DESTROY_SINCE: u32 = 3u32;
#[doc = r" The wire opcode for this request"]
Expand Down Expand Up @@ -1024,6 +1049,13 @@ pub mod tertiary {
.map(|data| &data.udata)
}
#[inline]
fn delegated_data<U: 'static, M: 'static>(&self) -> Option<&U> {
self.data
.as_ref()
.and_then(|arc| (&**arc).downcast_ref::<DelegatedResourceData<Self, U, M>>())
.map(|data| &data.udata)
}
#[inline]
fn object_data(&self) -> Option<&Arc<dyn std::any::Any + Send + Sync>> {
self.data.as_ref()
}
Expand Down Expand Up @@ -1092,10 +1124,11 @@ pub mod quad {
protocol::{same_interface, Argument, Interface, Message, WEnum},
smallvec, InvalidId, ObjectData, ObjectId, WeakHandle,
},
Dispatch, DispatchError, DisplayHandle, New, Resource, ResourceData, Weak,
DelegatedResourceData, Dispatch, DispatchError, DisplayHandle, New, Resource, ResourceData,
Weak,
};
use std::sync::Arc;
use std::os::unix::io::OwnedFd;
use std::sync::Arc;
#[doc = r" The minimal object version supporting this request"]
pub const REQ_DESTROY_SINCE: u32 = 3u32;
#[doc = r" The wire opcode for this request"]
Expand Down Expand Up @@ -1183,6 +1216,13 @@ pub mod quad {
.map(|data| &data.udata)
}
#[inline]
fn delegated_data<U: 'static, M: 'static>(&self) -> Option<&U> {
self.data
.as_ref()
.and_then(|arc| (&**arc).downcast_ref::<DelegatedResourceData<Self, U, M>>())
.map(|data| &data.udata)
}
#[inline]
fn object_data(&self) -> Option<&Arc<dyn std::any::Any + Send + Sync>> {
self.data.as_ref()
}
Expand Down
Loading

0 comments on commit 443cb1f

Please sign in to comment.