Skip to content

Commit

Permalink
Enums implement Default
Browse files Browse the repository at this point in the history
  • Loading branch information
mio991 committed Mar 9, 2023
1 parent ac5f78c commit f5f49cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions godot-codegen/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ pub fn make_enum_definition(enum_: &Enum) -> TokenStream {
#enumerators
)*
}
impl std::default::Default for #enum_name {
fn default() -> Self {
Self { ord: 0 }
}
}
impl crate::obj::EngineEnum for #enum_name {
// fn try_from_ord(ord: i32) -> Option<Self> {
// match ord {
Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/obj/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub trait EngineClass: GodotClass {
}

/// Auto-implemented for all engine-provided enums
pub trait EngineEnum: Copy {
pub trait EngineEnum: Copy + Default {
fn try_from_ord(ord: i32) -> Option<Self>;

/// Ordinal value of the enumerator, as specified in Godot.
Expand Down

0 comments on commit f5f49cd

Please sign in to comment.