Skip to content

Turbofish support for node.duplicate() #1421

@Relu-Avali

Description

@Relu-Avali

When duplicating a node of a known sub-node type such as

let original = Sprite2D.new_alloc();
let duplicate = original_node.duplicate().unwrap(); //will be of type Gd<Node> 
let cast_duplicate = duplicate.cast::<Sprite2D>();
//You can now do Sprite2D stuff with your duplicate here

the duplicate will be a Gd<Node> instead of the same type as the original. If you intend to do anything with the duplicate it will require down-casting to the type of the original. I suggest adding turbofish support for duplicate in order to reduce the number of required casts.

Example of suggestion:

let original = Sprite2D.new_alloc();
let my_duplicate = original_node.duplicate::<Sprite2D>();
//You can now do Sprite2D stuff with your duplicate here

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: coreCore componentsquality-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