@@ -71,12 +71,15 @@ use crate::{classes, out};
7171/// * [`Gd::from_instance_id(id)`][Gd::from_instance_id] and [`Gd::try_from_instance_id(id)`][Gd::try_from_instance_id]
7272/// to obtain a pointer to an object which is already alive in the engine.
7373///
74- /// # Binds
74+ /// # Bind guards
7575///
7676/// The [`bind()`][Self::bind] and [`bind_mut()`][Self::bind_mut] methods allow you to obtain a shared or exclusive guard to the user instance.
7777/// These provide interior mutability similar to [`RefCell`][std::cell::RefCell], with the addition that `Gd` simultaneously handles reference
7878/// counting (for some types `T`).
7979///
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+ ///
8083/// When you declare a `#[func]` method on your own class, and it accepts `&self` or `&mut self`, an implicit `bind()` or `bind_mut()` call
8184/// 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
8285/// 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
151154 /// `GodotClass` instance, independently of how many `Gd` smart pointers point to it. There are runtime
152155 /// checks to ensure that Rust safety rules (e.g. no `&` and `&mut` coexistence) are upheld.
153156 ///
157+ /// Drop the guard as soon as you don't need it anymore. See also [Bind guards](#bind-guards).
158+ ///
154159 /// # Panics
155160 /// * If another `Gd` smart pointer pointing to the same Rust instance has a live `GdMut` guard bound.
156161 /// * If there is an ongoing function call from GDScript to Rust, which currently holds a `&mut T`
@@ -167,6 +172,8 @@ where
167172 /// `GodotClass` instance, independently of how many `Gd` smart pointers point to it. There are runtime
168173 /// checks to ensure that Rust safety rules (e.g. no `&mut` aliasing) are upheld.
169174 ///
175+ /// Drop the guard as soon as you don't need it anymore. See also [Bind guards](#bind-guards).
176+ ///
170177 /// # Panics
171178 /// * If another `Gd` smart pointer pointing to the same Rust instance has a live `GdRef` or `GdMut` guard bound.
172179 /// * If there is an ongoing function call from GDScript to Rust, which currently holds a `&T` or `&mut T`
0 commit comments