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

Gd::upcast_ref() + Gd::upcast_mut() #558

Merged
merged 7 commits into from
Jan 7, 2024
Merged

Gd::upcast_ref() + Gd::upcast_mut() #558

merged 7 commits into from
Jan 7, 2024

Conversation

Bromeon
Copy link
Member

@Bromeon Bromeon commented Jan 7, 2024

Adds Gd::upcast_ref() and Gd::upcast_mut(). They have no direct use due to Deref trait, but can be useful in generic programming:

fn print_node_name<T>(node: &Gd<T>)
where
    T: Inherits<Node>,
{
    println!("Node name: {}", node.upcast_ref().get_name());
}

Also took the opportunity to clean up quite a few things around Deref and casting, which were handled entirely separately in the past. Most of the work is done -- there's still RawGd::with_ref_counted() which I'd like to align with as_object(), but I can't spend more time on this right now.

As a side effect, some of the object-swap checks (#23) now got even stricter. You can basically not do anything useful anymore, indicating that this is a bug that must always be fixed.

More details in commit messages.

Changes:

* Remove Declarer::scoped_mut() - no need to go through bind() for changes in base RefCounted;
  any accesses to user objects (e.g. destruction if refc=0) would bind anyway.

* DynMemory::maybe_*_ref() methods now accept &mut RawGd<T> instead of &RawGd<T>.
  This expresses the mutation that happens better.

* RawGd::as_object() returns &Object directly.

* Rename RawGd::as_ref_counted -> with_ref_counted.
@Bromeon Bromeon added feature Adds functionality to the library c: core Core components labels Jan 7, 2024
@Bromeon Bromeon changed the title Feature/upcast ref Gd::upcast_ref() + Gd::upcast_mut() Jan 7, 2024
@Bromeon Bromeon enabled auto-merge January 7, 2024 18:36
@GodotRust
Copy link

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-558

@Bromeon Bromeon added this pull request to the merge queue Jan 7, 2024
Merged via the queue into master with commit 292096c Jan 7, 2024
16 checks passed
@Bromeon Bromeon deleted the feature/upcast-ref branch January 7, 2024 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: core Core components feature Adds functionality to the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants