Skip to content

Commit 7cde5e9

Browse files
authored
Merge pull request #994 from SeaDve/docs-improve
glib-macros: slightly improve Properties macro docs
2 parents 3841f31 + 9233fe1 commit 7cde5e9

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

glib-macros/src/lib.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -850,24 +850,31 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {
850850

851851
/// This macro enables you to derive object properties in a quick way.
852852
///
853-
/// # Getters and setters
854-
/// By default, they are generated for you.
855-
/// You can use a custom getter/setter by assigning an expression to `get`/`set`.
856-
/// Example: `#[property(get = |_| 2, set)]`.
853+
/// # Generated wrapper methods
854+
/// The following methods are generated on the wrapper type specified on `#[properties(wrapper_type = ...)]`:
855+
/// * `$property()`, when the property is readable
856+
/// * `set_$property()`, when the property is writable and not construct-only
857+
/// * `connect_$property_notify()`
858+
/// * `notify_$property()`
857859
///
858-
/// The macro will always generate, on the wrapper type, the corresponding `$property()` and
859-
/// `set_$property()` methods.
860-
/// Notice: you can't reimplement the generated methods on the wrapper type, but you can change their
861-
/// behavior using a custom getter/setter.
860+
/// Notice: You can't reimplement the generated methods on the wrapper type,
861+
/// but you can change their behavior using a custom internal getter/setter.
862+
///
863+
/// # Internal getters and setters
864+
/// By default, they are generated for you. However, you can use a custom getter/setter
865+
/// by assigning an expression to `get`/`set`: `#[property(get = |_| 2, set)]` or `#[property(get, set = custom_setter_func)]`.
862866
///
863867
/// # Supported types
864868
/// Every type implementing the trait `Property` is supported.
869+
///
865870
/// If you want to support a custom type, you should consider implementing `Property` and
866871
/// `PropertyGet`. If your type supports interior mutability, you should implement also
867872
/// `PropertySet` and `PropertySetNested` if possible.
873+
///
868874
/// The type `Option<T>` is supported as a property only if `Option<T>` implements `ToValueOptional`.
869875
/// If your type doesn't support `PropertySet`, you can't use the generated setter, but you can
870876
/// always define a custom one.
877+
///
871878
/// If you want to support a custom type with a custom `ParamSpec`, you should implement the trait
872879
/// `HasParamSpec` instead of `Property`.
873880
///
@@ -916,16 +923,11 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {
916923
/// fn properties() -> &'static [ParamSpec] {
917924
/// Self::derived_properties()
918925
/// }
919-
/// fn set_property(
920-
/// &self,
921-
/// _id: usize,
922-
/// _value: &Value,
923-
/// _pspec: &ParamSpec,
924-
/// ) {
925-
/// Self::derived_set_property(self, _id, _value, _pspec)
926+
/// fn set_property(&self, id: usize, value: &Value, pspec: &ParamSpec) {
927+
/// self.derived_set_property(id, value, pspec)
926928
/// }
927-
/// fn property(&self, _id: usize, _pspec: &ParamSpec) -> Value {
928-
/// Self::derived_property(self, _id, _pspec)
929+
/// fn property(&self, id: usize, pspec: &ParamSpec) -> Value {
930+
/// self.derived_property(id, pspec)
929931
/// }
930932
/// }
931933
///

0 commit comments

Comments
 (0)