Skip to content

Commit 688ac92

Browse files
authored
Merge pull request #716 from lokimckay/patch-1
Add WithBaseField example to traits.rs (#715)
2 parents d093359 + f62a8cb commit 688ac92

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

godot-core/src/obj/traits.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,24 @@ pub trait IndexEnum: EngineEnum {
210210
/// Trait that's implemented for user-defined classes that provide a `Base<T>` field.
211211
///
212212
/// Gives direct access to the containing `Gd<Self>` from `Self`.
213+
///
214+
/// # Using WithBaseField as a bound
215+
///
216+
/// In order to call `self.base()` or `self.base_mut()` within a trait or on a type you define, the type of `Self::Base` must be specified via `WithBaseField<Base = T>`
217+
///
218+
/// E.g.
219+
///
220+
/// ```no_run
221+
/// # use godot::prelude::*;
222+
/// # use godot::obj::WithBaseField;
223+
/// fn some_fn<T>(value: &T)
224+
/// where
225+
/// T: WithBaseField<Base = Node3D>,
226+
/// {
227+
/// let base = value.base();
228+
/// }
229+
/// ```
230+
///
213231
// Possible alternative for builder APIs, although even less ergonomic: Base<T> could be Base<T, Self> and return Gd<Self>.
214232
#[diagnostic::on_unimplemented(
215233
message = "Class `{Self}` requires a `Base<T>` field",

0 commit comments

Comments
 (0)