Skip to content

Commit 543f38e

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 543f38e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

glib-macros/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,34 @@ 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+
///
528556
/// An enum can be registered as a dynamic type by setting the derive macro
529557
/// helper attribute `enum_dynamic`:
530558
///

0 commit comments

Comments
 (0)