Skip to content

Commit 83db6ed

Browse files
authored
Merge pull request #1062 from SeaDve/docs-impr
glib-macros: add docs on supported #[property] attributes
2 parents 684e087 + f86fba3 commit 83db6ed

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

glib-macros/src/lib.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,22 @@ 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
855+
/// | Attribute | Description | Default | Example |
856+
/// | --- | --- | --- | --- |
857+
/// | `name = "literal"` | The name of the property | field ident where `_` (leading and trailing `_` are trimmed) is replaced into `-` | `#[property(name = "prop-name")]` |
858+
/// | `type = expr` | The type of the property | inferred | `#[property(type = i32)]` |
859+
/// | `get [= expr]` | Specify that the property is readable and use `PropertyGet::get` [or optionally set a custom internal getter] | | `#[property(get)]`, `#[property(get = get_prop)]`, or `[property(get = \|_\| 2)]` |
860+
/// | `set [= expr]` | Specify that the property is writable and use `PropertySet::set` [or optionally set a custom internal setter] | | `#[property(set)]`, `#[property(set = set_prop)]`, or `[property(set = \|_, val\| {})]` |
861+
/// | `override_class = expr` | The type of class of which to override the property from | | `#[property(override_class = SomeClass)]` |
862+
/// | `override_interface = expr` | The type of interface of which to override the property from | | `#[property(override_interface = SomeInterface)]` |
863+
/// | `nullable` | Whether to use `Option<T>` in the wrapper's generated setter | | `#[property(nullable)]` |
864+
/// | `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. |
866+
/// | `default` | Sets the `default_value` field of the Param Spec builder | | `#[property(default = 1)]` |
867+
/// | `<optional-pspec-builder-fields> = expr` | Used to add optional Param Spec builder fields | | `#[property(minimum = 0)` , `#[property(minimum = 0, maximum = 1)]`, etc. |
868+
/// | `<optional-pspec-builder-fields>` | Used to add optional Param Spec builder fields | | `#[property(explicit_notify)]` , `#[property(construct_only)]`, etc. |
869+
///
854870
/// # Generated wrapper methods
855871
/// The following methods are generated on the wrapper type specified on `#[properties(wrapper_type = ...)]`:
856872
/// * `$property()`, when the property is readable
@@ -863,7 +879,7 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {
863879
///
864880
/// # Internal getters and setters
865881
/// By default, they are generated for you. However, you can use a custom getter/setter
866-
/// by assigning an expression to `get`/`set`: `#[property(get = |_| 2, set)]` or `#[property(get, set = custom_setter_func)]`.
882+
/// by assigning an expression to `get`/`set` #[property] attributes: `#[property(get = |_| 2, set)]` or `#[property(get, set = custom_setter_func)]`.
867883
///
868884
/// # Supported types
869885
/// Every type implementing the trait `Property` is supported.

0 commit comments

Comments
 (0)