@@ -71,12 +71,15 @@ use crate::{classes, out};
71
71
/// * [`Gd::from_instance_id(id)`][Gd::from_instance_id] and [`Gd::try_from_instance_id(id)`][Gd::try_from_instance_id]
72
72
/// to obtain a pointer to an object which is already alive in the engine.
73
73
///
74
- /// # Binds
74
+ /// # Bind guards
75
75
///
76
76
/// The [`bind()`][Self::bind] and [`bind_mut()`][Self::bind_mut] methods allow you to obtain a shared or exclusive guard to the user instance.
77
77
/// These provide interior mutability similar to [`RefCell`][std::cell::RefCell], with the addition that `Gd` simultaneously handles reference
78
78
/// counting (for some types `T`).
79
79
///
80
+ /// Holding a bind guard will prevent other code paths from obtaining their own shared/mutable bind. As such, you should drop the guard
81
+ /// as soon as you don't need it anymore, by closing a `{ }` block or calling `std::mem::drop()`.
82
+ ///
80
83
/// When you declare a `#[func]` method on your own class, and it accepts `&self` or `&mut self`, an implicit `bind()` or `bind_mut()` call
81
84
/// on the owning `Gd<T>` is performed. This is important to keep in mind, as you can get into situations that violate dynamic borrow rules; for
82
85
/// example if you are inside a `&mut self` method, make a call to GDScript and indirectly call another method on the same object (re-entrancy).
@@ -151,6 +154,8 @@ where
151
154
/// `GodotClass` instance, independently of how many `Gd` smart pointers point to it. There are runtime
152
155
/// checks to ensure that Rust safety rules (e.g. no `&` and `&mut` coexistence) are upheld.
153
156
///
157
+ /// Drop the guard as soon as you don't need it anymore. See also [Bind guards](#bind-guards).
158
+ ///
154
159
/// # Panics
155
160
/// * If another `Gd` smart pointer pointing to the same Rust instance has a live `GdMut` guard bound.
156
161
/// * If there is an ongoing function call from GDScript to Rust, which currently holds a `&mut T`
@@ -167,6 +172,8 @@ where
167
172
/// `GodotClass` instance, independently of how many `Gd` smart pointers point to it. There are runtime
168
173
/// checks to ensure that Rust safety rules (e.g. no `&mut` aliasing) are upheld.
169
174
///
175
+ /// Drop the guard as soon as you don't need it anymore. See also [Bind guards](#bind-guards).
176
+ ///
170
177
/// # Panics
171
178
/// * If another `Gd` smart pointer pointing to the same Rust instance has a live `GdRef` or `GdMut` guard bound.
172
179
/// * If there is an ongoing function call from GDScript to Rust, which currently holds a `&T` or `&mut T`
0 commit comments