godot-rust v0.4: export groups, match_class, easy callables, ...

136 points bromeon 5 comments

godot-rust version 0.4.0 makes the Godot engine even more approachable and pleasant to use in Rust!

Interop gets easier, for example:

// Old way (dynamically typed):
node.call_deferred("set_position", &[pos.to_variant()]);

// New way (type-safe):
node.run_deferred_gd(|obj| obj.set_position(pos));

We leverage Rust's strengths, by adding generics where even Godot doesn't have them, e.g. in PackedArray:

// Works for all Packed*Array objects:
fn format_array<T>(array: &PackedArray<T>) -> String {...}

Well-proven Rust features like match inspired the library to extend this to Godot class hierarchies, avoiding tedious downcast chains:

match_class!(event, {
    button @ InputEventMouseButton => { ... },
    motion @ InputEventMouseMotion => { ... }
    action @ InputEventAction => { ... }
    _ => { ... } // fallback
});

Huge thanks to the great community making this possible!