Hi all, Jumping into the discussion. Please bear with me knowing that I consider myself a Rust newbie O:-) On Wed, 25 Oct 2017 13:20:44 -0500, Federico Mena Quintero <federico gnome org> wrote:
On Wed, 2017-10-25 at 10:41 +0200, Sebastian Dröge wrote: [...][...] #[attributes...] property some_property: u32 { get(&self) -> u32 { self.something } set(&self, value: u32) { self.something = value; } } } Maybe? Not sure about providing the type 3 times, but this way seems most consistent.Makes sense. I'll look more closely at Vala. From it and from C# I don't like the magic "value" that it uses inside setters; it appears to come from nowhere. Would "_" make sense just avoid repeating the type?
It can be nice for types with long names. Some shorthand would be nice, but the underscore is used in Rust for pattern-matching “anything”, and the matched value gets discarded. An alternative could be allowing the user to alias the type by using “where”: property some_property: T where T: u32 { get(&self) -> T { self.private().foo } set(&self, value: T) { self.private().foo = value; } }
property some_property: u32 { get(&self) -> _ { self.private().foo } set(&self, value: _) { self.private().foo = value; } }
For this kind of simple getters... Wouldn't it make sense to provide a way of “synthesizing” their implementation? Example: // The derived/synthesized gettter and setter use the "foo" field // of the private struct automatically. #[derive(get, set)] property foo: u32 { } // If one of them needs to do additinal work, only that has to be // explicitly implemented. #[derive(get)] property foo: u32 { set(&self, value: u32) { self.private().foo = value; self.notify_foo_observers(); } } Note that I am suggesting that whether a getter/setter exists would still be explicit, and therefore it remains possible to create properties which only have a getter or a setter. BTW, great work on the whole big task of making usage of GObject inside Rust idiomatic \o/ Cheers, -- Adrián 🎩
Attachment:
pgpPTyGRW2tUo.pgp
Description: PGP signature