Skip to content

Commit a392143

Browse files
committed
glib-macros: Update the doc of the Properties macro to elaborate on usage of keywords as property names
1 parent fd2e99f commit a392143

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

glib-macros/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,10 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {
867867
/// | `<optional-pspec-builder-fields> = expr` | Used to add optional Param Spec builder fields | | `#[property(minimum = 0)` , `#[property(minimum = 0, maximum = 1)]`, etc. |
868868
/// | `<optional-pspec-builder-fields>` | Used to add optional Param Spec builder fields | | `#[property(explicit_notify)]` , `#[property(construct_only)]`, etc. |
869869
///
870+
/// ## Using Rust keywords as property names
871+
/// You might hit a roadblock when declaring properties with this macro because you want to use a name that happens to be a Rust keyword. This may happen with names like `loop`, which is a pretty common name when creating things like animation handlers.
872+
/// To use those names, you can make use of the raw identifier feature of Rust. Simply prefix the identifier name with `r#` in the struct declaration. Internally, those `r#`s are stripped so you can use its expected name in [`ObjectExt::property`] or within GtkBuilder template files.
873+
///
870874
/// # Generated wrapper methods
871875
/// The following methods are generated on the wrapper type specified on `#[properties(wrapper_type = ...)]`:
872876
/// * `$property()`, when the property is readable

0 commit comments

Comments
 (0)