Skip to content

Commit aeac5af

Browse files
committed
docs(ExportEnum): add macro doc
1 parent 5b2e639 commit aeac5af

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

gdnative-derive/src/lib.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,52 @@ pub fn godot_wrap_method(input: TokenStream) -> TokenStream {
668668
}
669669
}
670670

671+
/// Make a rust `enum` has drop-down list in Godot editor.
672+
/// Note that the derived `enum` should also implements `Copy` trait.
673+
///
674+
/// Take the following example, you will see a drop-down list for the `dir`
675+
/// property, and `Up` and `Down` converts to `1` and `-1` in the GDScript
676+
/// side.
677+
///
678+
/// ```
679+
/// use gdnative::prelude::*;
680+
///
681+
/// #[derive(Debug, PartialEq, Clone, Copy, ExportEnum)]
682+
/// enum Dir {
683+
/// Up = 1,
684+
/// Down = -1,
685+
/// }
686+
///
687+
/// #[derive(NativeClass)]
688+
/// #[no_constructor]
689+
/// struct Move {
690+
/// #[property]
691+
/// pub dir: Dir,
692+
/// }
693+
/// ```
694+
///
695+
/// You can't derive `ExportEnum` on `enum` that has non-unit variant.
696+
///
697+
/// ```compile_fail
698+
/// use gdnative::prelude::*;
699+
///
700+
/// #[derive(Debug, PartialEq, Clone, Copy, ExportEnum)]
701+
/// enum Action {
702+
/// Move((f32, f32, f32)),
703+
/// Attack(u64),
704+
/// }
705+
/// ```
706+
///
707+
/// You can't derive `ExportEnum` on `struct` or `union`.
708+
///
709+
/// ```compile_fail
710+
/// use gdnative::prelude::*;
711+
///
712+
/// #[derive(ExportEnum)]
713+
/// struct Foo {
714+
/// f1: i32
715+
/// }
716+
/// ```
671717
#[proc_macro_derive(ExportEnum)]
672718
pub fn derive_export_enum(input: TokenStream) -> TokenStream {
673719
let derive_input = syn::parse_macro_input!(input as syn::DeriveInput);

0 commit comments

Comments
 (0)