From f62a8cb61b443f6b5b91afe7ee7df541c6d2b2b7 Mon Sep 17 00:00:00 2001 From: Loki McKay Date: Sun, 19 May 2024 12:18:52 +1000 Subject: [PATCH] Add WithBaseField example to traits.rs (#715) --- godot-core/src/obj/traits.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/godot-core/src/obj/traits.rs b/godot-core/src/obj/traits.rs index 0888efc89..5c05bf39f 100644 --- a/godot-core/src/obj/traits.rs +++ b/godot-core/src/obj/traits.rs @@ -210,6 +210,24 @@ pub trait IndexEnum: EngineEnum { /// Trait that's implemented for user-defined classes that provide a `Base` field. /// /// Gives direct access to the containing `Gd` from `Self`. +/// +/// # Using WithBaseField as a bound +/// +/// 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` +/// +/// E.g. +/// +/// ```no_run +/// # use godot::prelude::*; +/// # use godot::obj::WithBaseField; +/// fn some_fn(value: &T) +/// where +/// T: WithBaseField, +/// { +/// let base = value.base(); +/// } +/// ``` +/// // Possible alternative for builder APIs, although even less ergonomic: Base could be Base and return Gd. #[diagnostic::on_unimplemented( message = "Class `{Self}` requires a `Base` field",