Skip to content

Commit

Permalink
glib-macros: Update docs for the properties macro construct_only attr…
Browse files Browse the repository at this point in the history
…ibute
  • Loading branch information
felinira authored and sdroege committed Jun 6, 2023
1 parent 7a8d5ad commit 00a170a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
7 changes: 4 additions & 3 deletions glib-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {

/// This macro enables you to derive object properties in a quick way.
///
/// # Supported #[property] attributes
/// # Supported `#[property]` attributes
/// | Attribute | Description | Default | Example |
/// | --- | --- | --- | --- |
/// | `name = "literal"` | The name of the property | field ident where `_` (leading and trailing `_` are trimmed) is replaced into `-` | `#[property(name = "prop-name")]` |
Expand All @@ -862,7 +862,8 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {
/// | `override_interface = expr` | The type of interface of which to override the property from | | `#[property(override_interface = SomeInterface)]` |
/// | `nullable` | Whether to use `Option<T>` in the wrapper's generated setter | | `#[property(nullable)]` |
/// | `member = ident` | Field of the nested type where property is retrieved and set | | `#[property(member = author)]` |
/// | `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. |
/// | `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)]` |
/// | `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. |
/// | `default` | Sets the `default_value` field of the Param Spec builder | | `#[property(default = 1)]` |
/// | `<optional-pspec-builder-fields> = expr` | Used to add optional Param Spec builder fields | | `#[property(minimum = 0)` , `#[property(minimum = 0, maximum = 1)]`, etc. |
/// | `<optional-pspec-builder-fields>` | Used to add optional Param Spec builder fields | | `#[property(explicit_notify)]` , `#[property(construct_only)]`, etc. |
Expand All @@ -883,7 +884,7 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {
///
/// # Internal getters and setters
/// By default, they are generated for you. However, you can use a custom getter/setter
/// by assigning an expression to `get`/`set` #[property] attributes: `#[property(get = |_| 2, set)]` or `#[property(get, set = custom_setter_func)]`.
/// by assigning an expression to `get`/`set` `#[property]` attributes: `#[property(get = |_| 2, set)]` or `#[property(get, set = custom_setter_func)]`.
///
/// # Supported types
/// Every type implementing the trait `Property` is supported.
Expand Down
15 changes: 5 additions & 10 deletions glib-macros/src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,11 @@ impl PropDesc {
builder_fields,
} = attrs;

let is_construct_only = if builder_fields.iter().any(|(k, _)| *k == "construct_only") {
// Insert a default setter automatically
if set.is_none() {
set = Some(MaybeCustomFn::Default);
}

true
} else {
false
};
let is_construct_only = builder_fields.iter().any(|(k, _)| *k == "construct_only");
if is_construct_only && set.is_none() {
// Insert a default internal setter automatically
set = Some(MaybeCustomFn::Default);
}

if get.is_none() && set.is_none() {
return Err(syn::Error::new(
Expand Down

0 comments on commit 00a170a

Please sign in to comment.