Skip to content

Commit f21daf7

Browse files
committed
Clarify usage requirement of Properties macro for enum types
1 parent 63875ab commit f21daf7

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

glib-macros/src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,9 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {
13661366
/// Optional types also require the `nullable` attribute: without it, the generated setter on the wrapper type
13671367
/// will take `T` instead of `Option<T>`, preventing the user from ever calling the setter with a `None` value.
13681368
///
1369+
/// Notice: For enums that derive [`Enum`] or are C-style enums, you must explicitly specify the
1370+
/// default value of the enum using the `builder` parameter in the `#[property]` attribute.
1371+
///
13691372
/// ## Adding support for custom types
13701373
/// ### Types wrapping an existing <code>T: [ToValue] + [HasParamSpec]</code>
13711374
/// If you have declared a newtype as
@@ -1390,7 +1393,7 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {
13901393
///
13911394
/// # Example
13921395
/// ```
1393-
/// use std::cell::RefCell;
1396+
/// use std::cell::{Cell, RefCell};
13941397
/// use glib::prelude::*;
13951398
/// use glib::subclass::prelude::*;
13961399
/// use glib_macros::Properties;
@@ -1401,6 +1404,13 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {
14011404
/// nick: String,
14021405
/// }
14031406
///
1407+
/// #[derive(Debug, Copy, Clone, PartialEq, Eq, glib::Enum)]
1408+
/// #[enum_type(name = "MyEnum")]
1409+
/// enum MyEnum {
1410+
/// Val,
1411+
/// OtherVal
1412+
/// }
1413+
///
14041414
/// pub mod imp {
14051415
/// use std::rc::Rc;
14061416
///
@@ -1426,6 +1436,8 @@ pub fn cstr_bytes(item: TokenStream) -> TokenStream {
14261436
/// optional: RefCell<Option<String>>,
14271437
/// #[property(get, set)]
14281438
/// smart_pointer: Rc<RefCell<String>>,
1439+
/// #[property(get, set, builder(MyEnum::Val))]
1440+
/// my_enum: Cell<MyEnum>,
14291441
/// /// # Getter
14301442
/// ///
14311443
/// /// Get the value of the property `extra_comments`

0 commit comments

Comments
 (0)