-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Add glib::signals! macro #1577
base: main
Are you sure you want to change the base?
Add glib::signals! macro #1577
Conversation
2fd3218
to
7e0eff9
Compare
#[glib::derived_properties] | ||
impl ObjectImpl for Author { | ||
fn signals() -> &'static [Signal] { | ||
static SIGNALS: OnceLock<Vec<Signal>> = OnceLock::new(); | ||
SIGNALS.get_or_init(|| vec![Signal::builder("awarded").build()]) | ||
Self::derived_signals() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to add a derived_signals macro as well, not much work and would make the migration to use the future signals macro more appealing
For the connect_ functions, you would have to use Something that I haven't seen any note about is the signal details, not sure how to handle it. |
impl Author { | ||
|
||
#[signal] | ||
fn awarded(&self) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would be possible to make
fn awarded(&self) {} | |
fn awarded(&self); |
and that means that the signal has no class handler, and
fn awarded(&self) {} | |
fn awarded(&self) { println!("stuff"); } |
which means that it has a class handler with the body of the function.
In the first case, the macro would have to remove the whole function after expansion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I almost never use class handlers in my signals so I would appreciate something like that too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A function without a block isn't valid rust syntax outside of an extern
block. I don't want to add some invalid Syntax that would be removed by the macro.
It's also way more complicated to parse this. I would have to write a custom parser based on syn::ItemImpl
that accepts these "invalid" functions. And it confuses other parsing code for other macros or rustfmt.
I can add and parse a toplevel pseudo-macro, meaning something like this would be ok:
#[glib::signals(wrapper_type = super::FooObject)]
impl FooObject {
signals! {
fn awarded() -> i32;
}
}
This pseudo-macro is valid Rust Syntax and should work with rustfmt and other macros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of using an impl Object
, the usage could be trait ObjectSignals
making it possible to provide a default impl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default implementations can only use methods provided by the trait's required subtraits and itself.
The class handler implementations would have to reside in an impl ObjectSignals for FooObject
block.
I don't really see how I'd map a trait to a definition of signals, as I don't want the macro to modify the trait in ways that make it hard for a developer to understand what the trait will actually look like.
The problem I see is that a semicolon instead of a block in a trait definition means that you have to provide the class handler in your implementation of that trait, while you want it to mean that there is no class handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trait itself wouldn't be used. You can then impl T for SomeObject
and forward the calls when the trait has an impl, no?
Anyways, zbus is using something similar for it zbus::proxy! macro.
This should only be done for non- |
It's not called at all AFAICS (see |
This is my initial implementation of the ideas from #214 (comment) and currently only creates an implementation of a
DerivedObjectSignals
trait modeled after theDerivedObjectProperties
used by theProperties
macro. It needs some cleanup (a couple of unused elements/fields/imports) and it's also missing the generator for the connect_ and emit_ functions.The basics seem to work. But I'm now wondering how exactly signal class handlers work. Is the class handler function invoked if none of
run_first
,run_last
orrun_cleanup
are specified?