Skip to content

Commit d6571fc

Browse files
authored
Merge pull request #969 from ranfdev/props_clean
Improve properties macro docs
2 parents e73ff61 + 5e722d7 commit d6571fc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

glib-macros/src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,29 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {
848848
.unwrap_or_else(|e| e.into_compile_error().into())
849849
}
850850

851+
/// This macro enables you to derive object properties in a quick way.
852+
///
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)]`.
857+
///
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.
862+
///
863+
/// # Supported types
864+
/// Every type implementing the trait `Property` is supported.
865+
/// If you want to support a custom type, you should consider implementing `Property` and
866+
/// `PropertyGet`. If your type supports interior mutability, you should implement also
867+
/// `PropertySet` and `PropertySetNested` if possible.
868+
/// The type `Option<T>` is supported as a property only if `Option<T>` implements `ToValueOptional`.
869+
/// If your type doesn't support `PropertySet`, you can't use the generated setter, but you can
870+
/// always define a custom one.
871+
/// If you want to support a custom type with a custom `ParamSpec`, you should implement the trait
872+
/// `HasParamSpec` instead of `Property`.
873+
///
851874
/// # Example
852875
/// ```
853876
/// use std::cell::RefCell;

0 commit comments

Comments
 (0)