Skip to content

Commit 23c02ea

Browse files
committed
Document requirement for explicit default in Enum properties
When using the `Property` macro with enum types that derive `Enum`, the default value must be explicitly set using `#[property(builder(...))]`.
1 parent 63875ab commit 23c02ea

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

glib-macros/src/lib.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,35 @@ pub fn closure_local(item: TokenStream) -> TokenStream {
525525
/// }
526526
/// ```
527527
///
528+
/// When using [`Properties`] with an enum that derives [`Enum`], the default
529+
/// value must be explicitly set via the `builder` parameter of the
530+
/// `#[property]` attribute.
531+
///
532+
/// ```ignore
533+
/// use glib::prelude::*;
534+
/// use glib::subclass::prelude::*;
535+
///
536+
/// #[derive(Debug, Copy, Clone, PartialEq, Eq, glib::Enum)]
537+
/// #[enum_type(name = "MyEnum")]
538+
/// enum MyEnum {
539+
/// Val,
540+
/// ...
541+
/// }
542+
///
543+
/// mod imp {
544+
/// use std::cell::Cell;
545+
///
546+
/// #[derive(Debug, Default, glib::Properties)]
547+
/// #[properties(wrapper_type = super::MyObject)]
548+
/// pub MyObject {
549+
/// #[property(get, set, builder(MyEnum::Val))]
550+
/// my_enum: Cell<MyEnum>,
551+
/// ...
552+
/// }
553+
/// ...
554+
/// }
555+
/// ```
556+
///
528557
/// An enum can be registered as a dynamic type by setting the derive macro
529558
/// helper attribute `enum_dynamic`:
530559
///

0 commit comments

Comments
 (0)