Skip to content

Commit e7ac3be

Browse files
felinirabilelmoussaoui
authored andcommitted
glib-macros: Update docs for the properties macro construct_only attribute
1 parent babbc2a commit e7ac3be

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

glib-macros/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {
851851

852852
/// This macro enables you to derive object properties in a quick way.
853853
///
854-
/// # Supported #[property] attributes
854+
/// # Supported `#[property]` attributes
855855
/// | Attribute | Description | Default | Example |
856856
/// | --- | --- | --- | --- |
857857
/// | `name = "literal"` | The name of the property | field ident where `_` (leading and trailing `_` are trimmed) is replaced into `-` | `#[property(name = "prop-name")]` |
@@ -862,7 +862,8 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {
862862
/// | `override_interface = expr` | The type of interface of which to override the property from | | `#[property(override_interface = SomeInterface)]` |
863863
/// | `nullable` | Whether to use `Option<T>` in the wrapper's generated setter | | `#[property(nullable)]` |
864864
/// | `member = ident` | Field of the nested type where property is retrieved and set | | `#[property(member = author)]` |
865-
/// | `builder(<required-params>)[.ident]*` | Used to input required params or add optional Param Spec builder fields | | `#[property(builder(SomeEnum::default()))]`, `#[builder().default_value(1).construct_only()]`, etc. |
865+
/// | `construct_only` | Specify that the property is construct only. This will not generate a public setter and only allow the property to be set during object construction. The use of a custom internal setter is supported. | | `#[property(get, construct_only)]` or `#[property(get, set = set_prop, construct_only)]` |
866+
/// | `builder(<required-params>)[.ident]*` | Used to input required params or add optional Param Spec builder fields | | `#[property(builder(SomeEnum::default()))]`, `#[builder().default_value(1).minimum(0).maximum(5)]`, etc. |
866867
/// | `default` | Sets the `default_value` field of the Param Spec builder | | `#[property(default = 1)]` |
867868
/// | `<optional-pspec-builder-fields> = expr` | Used to add optional Param Spec builder fields | | `#[property(minimum = 0)` , `#[property(minimum = 0, maximum = 1)]`, etc. |
868869
/// | `<optional-pspec-builder-fields>` | Used to add optional Param Spec builder fields | | `#[property(explicit_notify)]` , `#[property(construct_only)]`, etc. |
@@ -883,7 +884,7 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {
883884
///
884885
/// # Internal getters and setters
885886
/// By default, they are generated for you. However, you can use a custom getter/setter
886-
/// by assigning an expression to `get`/`set` #[property] attributes: `#[property(get = |_| 2, set)]` or `#[property(get, set = custom_setter_func)]`.
887+
/// by assigning an expression to `get`/`set` `#[property]` attributes: `#[property(get = |_| 2, set)]` or `#[property(get, set = custom_setter_func)]`.
887888
///
888889
/// # Supported types
889890
/// Every type implementing the trait `Property` is supported.

glib-macros/src/properties.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,11 @@ impl PropDesc {
259259
builder_fields,
260260
} = attrs;
261261

262-
let is_construct_only = if builder_fields.iter().any(|(k, _)| *k == "construct_only") {
263-
// Insert a default setter automatically
264-
if set.is_none() {
265-
set = Some(MaybeCustomFn::Default);
266-
}
267-
268-
true
269-
} else {
270-
false
271-
};
262+
let is_construct_only = builder_fields.iter().any(|(k, _)| *k == "construct_only");
263+
if is_construct_only && set.is_none() {
264+
// Insert a default internal setter automatically
265+
set = Some(MaybeCustomFn::Default);
266+
}
272267

273268
if get.is_none() && set.is_none() {
274269
return Err(syn::Error::new(

0 commit comments

Comments
 (0)