Skip to content

Commit b0762e9

Browse files
bors[bot]mio991
andauthored
Merge #162
162: Enums implement Default r=Bromeon a=mio991 Adds a `Default` implementation for Enums. This came about because I wanted to use [`ArrayMesh::add_surface_from_arrays`](https://docs.godotengine.org/en/stable/classes/class_arraymesh.html#class-arraymesh-method-add-surface-from-arrays) with `SurfaceTool::commit_to_arrays` but had no idea which `ArrayFormat` to use. In the docs the default value is `0`. Co-authored-by: mio991 <[email protected]>
2 parents 1dcbc40 + 62f0f8b commit b0762e9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

godot-codegen/src/util.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,20 @@ pub fn make_enum_definition(enum_: &Enum) -> TokenStream {
5858
None
5959
};
6060

61+
let mut derives = vec!["Copy", "Clone", "Eq", "PartialEq", "Debug", "Hash"];
62+
63+
if enum_.is_bitfield {
64+
derives.push("Default");
65+
}
66+
67+
let derives = derives.into_iter().map(ident);
68+
6169
// Enumerator ordinal stored as i32, since that's enough to hold all current values and the default repr in C++.
6270
// Public interface is i64 though, for consistency (and possibly forward compatibility?).
6371
// TODO maybe generalize GodotFfi over EngineEnum trait
6472
quote! {
6573
#[repr(transparent)]
66-
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
74+
#[derive(#( #derives ),*)]
6775
pub struct #enum_name {
6876
ord: i32
6977
}

0 commit comments

Comments
 (0)