Skip to content

Generated enum getters and setters should return the enum type in Rust #1358

@jsternberg

Description

@jsternberg

When creating an enum such as the following:

#[derive(GodotConvert, Var, Export, Clone, Copy)]
#[godot(via = u8)]
pub enum WeaponType {
    Axe,
    Sword,
    Lance,
}

If you then use the enum as an export/var.

#[derive(GodotClass)]
#[class(init, base=Node)]
pub struct MyCustomNode {
    base: Base<Node>,
    #[export]
    weapon_type: WeaponType,
}

The generated getter and setter for this uses the Via type instead of the enum. This results in the following code getting sprinkled around in Rust.

let weapon_type = MyCustomNode::from_godot(my_node.bind().get_weapon_type());

This can be a lot to type from an ergonomics perspective. It would be nice if there was a way to have the getters and setters use the enum type directly instead of the <T as GodotConvert>::Via type or to have some alternative method or way to go about writing the above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: registerRegister classes, functions and other symbols to GDScriptquality-of-lifeNo new functionality, but improves ergonomics/internals

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions