-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Properties macro #494
Properties macro #494
Conversation
I would not use the flags directly but make them separate attributes like (read/write/notify) and map them internally to the corresponding flag |
Vala supports two types of properties (https://wiki.gnome.org/Projects/Vala/Manual/Classes#Properties):
So properties can be backed in something like a In addition to properties, GObject has signals, and I think the two should be considered together. (I wrote an idea for signals in #214). Luckily signals are simpler in comparison. |
The latest API is: #[derive(Props, Default)]
pub struct Foo {
#[prop(get, set)]
bar: Mutex<String>,
#[prop(get = Self::hello_world)]
_buzz: RefCell<String>,
#[prop(get, set = Self::set_fizz, name = "fizz")]
fizz: RefCell<String>,
} |
Nice to see someone working on this! 😃 It's looking good, I was thinking about this for the last few months and I had a few ideas:
|
This is already implemented:
Yes, I could do it, makes sense.
The general opinion is "yes". My current idea is to define a trait |
Sorry @jf2048, I misread. You actually want to generate getters/setters on the wrapper type. I don't know if this is technically possible. |
Well, the code suggested by @jf2048 should actually work just fine because it doesn't |
That syntax is invalid: impl <#name as ObjectSubclass>::Type {
fn hi() {}
}
Explanation: https://stackoverflow.com/questions/49277733/what-is-a-nominal-type-in-the-context-of-an-inherent-implementation |
@ranfdev right, but you can generate a trait and implement it for T::Type no? |
That's what I was getting at, I have been able to do that in some of my experiments. Sorry I should have been clearer, my code above was some really rough pseudocode. |
Yes, I thought about it, but then when you import the type you must import the related trait too, else you don't get access to any method. It's the best option for now, but it's not perfect |
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.
Sorry, reviewing from phone is hard
9185a95
to
b9a3d34
Compare
b848e97
to
c678ad6
Compare
19b6eca
to
0e44f5d
Compare
A feature I see missing is a way to create a property with a WeakRef. |
To move this forward, maybe this PR can be split up a bit? Let's first try to get those paramspec traits merged, for example. That way it can all be reviewed in smaller chunks. |
Would you mind rebasing this PR & fixing the test failure? |
9bb93fd
to
438406d
Compare
f8dc3b1
to
0b6951d
Compare
dd7d7ce
to
a799fe9
Compare
The macro would simplify the creation of properties and generate traits that can be used in ObjectImpl for now until further integration with signals & the rest of GObject creation is figured out.
a799fe9
to
3d98ec1
Compare
The implementation is a mess... I will clean it up.
Take a look at the newly added test case to see how it can be used.
I'm interested in comments about the API:
Currently you can't set more than one flag at a time. Everything else seems to work. Oh, and I need to finish implementing the
Parametrize
trait for all the type that have aParamSpec
.Related to #27