Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Inherits<T> reflexive, with implied GodotClass bound #116

Merged
merged 1 commit into from
Feb 5, 2023

Conversation

Bromeon
Copy link
Member

@Bromeon Bromeon commented Feb 5, 2023

Previously, it was hard to express polymorphism such as "anything that is a Node", including both Node and derived classes (for example in function parameters).

This is now straightforward and also doesn't require a GodotClass bound anymore:

fn print_node<T>(node: Gd<T>)
    where T: Inherits<Node>
{
    let node = node.upcast(); // Gd<Node> inferred
    ... // use it
}

Also adds a couple of tests, as well as a minor panic improvement when invoking Godot from test/doctest.

@Bromeon Bromeon added quality-of-life No new functionality, but improves ergonomics/internals c: core Core components labels Feb 5, 2023
Previously, it was hard to express polymorphism such as "anything that is a Node",
including both Node and derived classes (for example in function parameters).

This is now straightforward and also doesn't require a GodotClass bound anymore:

    fn print_node<T: Inherits<Node>>(node: Gd<T>)
    {
        ...
    }
@Bromeon Bromeon force-pushed the qol/reflexive-inherits branch from 275aae9 to ab23590 Compare February 5, 2023 21:45
@Bromeon
Copy link
Member Author

Bromeon commented Feb 5, 2023

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 5, 2023

Build succeeded:

  • full-ci

@bors bors bot merged commit b2f75f8 into master Feb 5, 2023
@bors bors bot deleted the qol/reflexive-inherits branch February 5, 2023 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: core Core components quality-of-life No new functionality, but improves ergonomics/internals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant