Skip to content

Commit 735d88f

Browse files
authored
Merge pull request #960 from godot-rust/qol/helpful-aliases
Helpful doc aliases: `func`, `var`, `init`, ...
2 parents d32d569 + 96916fa commit 735d88f

File tree

7 files changed

+48
-8
lines changed

7 files changed

+48
-8
lines changed

godot-core/src/builtin/math/float.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ mod private {
1616
impl Sealed for f64 {}
1717
}
1818

19+
/// Trait that provides Godot math functions as extensions on `f32` and `f64`.
1920
pub trait FloatExt: private::Sealed + Copy {
2021
const CMP_EPSILON: Self;
2122

godot-core/src/init/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ fn gdext_on_level_deinit(level: InitLevel) {
226226
/// [gdextension]: attr.gdextension.html
227227
/// [safety]: https://godot-rust.github.io/book/gdext/advanced/safety.html
228228
// FIXME intra-doc link
229+
#[doc(alias = "entry_symbol", alias = "entry_point")]
229230
pub unsafe trait ExtensionLibrary {
230231
/// Determines if and how an extension's code is run in the editor.
231232
fn editor_run_behavior() -> EditorRunBehavior {

godot-core/src/meta/godot_convert/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::meta::GodotType;
2121
/// in Godot (without intermediate "via"). Every `GodotType` also implements `GodotConvert` with `Via = Self`.
2222
///
2323
/// Please read the [`godot::meta` module docs][crate::meta] for further information about conversions.
24+
#[doc(alias = "via", alias = "transparent")]
2425
#[diagnostic::on_unimplemented(
2526
message = "`GodotConvert` is needed for `#[func]` parameters/returns, as well as `#[var]` and `#[export]` properties",
2627
note = "check following errors for more information"
@@ -39,6 +40,8 @@ pub trait GodotConvert {
3940
/// Violating these assumptions is safe but will give unexpected results.
4041
///
4142
/// Please read the [`godot::meta` module docs][crate::meta] for further information about conversions.
43+
///
44+
/// This trait can be derived using the [`#[derive(GodotConvert)]`](../register/derive.GodotConvert.html) macro.
4245
pub trait ToGodot: Sized + GodotConvert {
4346
/// Target type of [`to_godot()`](ToGodot::to_godot), which can differ from [`Via`][GodotConvert::Via] for pass-by-reference types.
4447
///
@@ -71,6 +74,8 @@ pub trait ToGodot: Sized + GodotConvert {
7174
/// Violating these assumptions is safe but will give unexpected results.
7275
///
7376
/// Please read the [`godot::meta` module docs][crate::meta] for further information about conversions.
77+
///
78+
/// This trait can be derived using the [`#[derive(GodotConvert)]`](../register/derive.GodotConvert.html) macro.
7479
pub trait FromGodot: Sized + GodotConvert {
7580
/// Converts the Godot representation to this type, returning `Err` on failure.
7681
fn try_from_godot(via: Self::Via) -> Result<Self, ConvertError>;

godot-core/src/registry/property.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@ use crate::meta::{ClassName, FromGodot, GodotConvert, GodotType, PropertyHintInf
1414
// ----------------------------------------------------------------------------------------------------------------------------------------------
1515
// Trait definitions
1616

17-
/// Trait implemented for types that can be used as `#[var]` fields.
17+
// Note: HTML link for #[var] works if this symbol is inside prelude, but not in register::property.
18+
/// Trait implemented for types that can be used as [`#[var]`](../register/derive.GodotClass.html#properties-and-exports) fields.
1819
///
1920
/// This creates a copy of the value, according to copy semantics provided by `Clone`. For example, `Array`, `Dictionary` and `Gd` are
2021
/// returned by shared reference instead of copying the actual data.
2122
///
2223
/// This does not require [`FromGodot`] or [`ToGodot`], so that something can be used as a property even if it can't be used in function
2324
/// arguments/return types.
25+
///
26+
/// See also [`Export`], a specialization of this trait for properties exported to the editor UI.
27+
///
28+
/// For enums, this trait can be derived using the [`#[derive(Var)]`](../derive.Var.html) macro.
29+
#[doc(alias = "property")]
30+
//
2431
// on_unimplemented: we also mention #[export] here, because we can't control the order of error messages.
2532
// Missing Export often also means missing Var trait, and so the Var error message appears first.
2633
#[diagnostic::on_unimplemented(
@@ -39,10 +46,15 @@ pub trait Var: GodotConvert {
3946
}
4047
}
4148

42-
/// Trait implemented for types that can be used as `#[export]` fields.
49+
// Note: HTML link for #[export] works if this symbol is inside prelude, but not in register::property.
50+
/// Trait implemented for types that can be used as [`#[export]`](../register/derive.GodotClass.html#properties-and-exports) fields.
4351
///
4452
/// `Export` is only implemented for objects `Gd<T>` if either `T: Inherits<Node>` or `T: Inherits<Resource>`, just like GDScript.
4553
/// This means you cannot use `#[export]` with `Gd<RefCounted>`, for example.
54+
///
55+
/// For enums, this trait can be derived using the [`#[derive(Export)]`](../derive.Export.html) macro.
56+
#[doc(alias = "property")]
57+
//
4658
// on_unimplemented: mentioning both Var + Export; see above.
4759
#[diagnostic::on_unimplemented(
4860
message = "`#[var]` properties require `Var` trait; #[export] ones require `Export` trait",

godot-macros/src/derive/derive_godot_convert.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
7+
78
use crate::derive::data_models::GodotConvert;
89
use crate::derive::{make_fromgodot, make_togodot};
910
use crate::ParseResult;

godot-macros/src/lib.rs

+25-5
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ use crate::util::{bail, ident, KvParser};
148148
/// [properties](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html#properties-setters-and-getters)
149149
/// (fields with a `get` or `set` declaration) and
150150
/// [exports](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_exports.html)
151-
/// (fields annotated with `@export`). In the gdext API, these two concepts are represented with `#[var]` and `#[export]` attributes respectively.
151+
/// (fields annotated with `@export`). In the gdext API, these two concepts are represented with `#[var]` and `#[export]` attributes respectively,
152+
/// which in turn are backed by the [`Var`](../register/property/trait.Var.html) and [`Export`](../register/property/trait.Export.html) traits.
152153
///
153154
/// ## Property registration
154155
///
@@ -474,7 +475,17 @@ use crate::util::{bail, ident, KvParser};
474475
/// }
475476
/// }
476477
/// ```
477-
#[proc_macro_derive(GodotClass, attributes(class, base, hint, var, export, init, signal))]
478+
#[doc(
479+
alias = "class",
480+
alias = "base",
481+
alias = "init",
482+
alias = "no_init",
483+
alias = "var",
484+
alias = "export",
485+
alias = "tool",
486+
alias = "rename"
487+
)]
488+
#[proc_macro_derive(GodotClass, attributes(class, base, hint, var, export, init))]
478489
pub fn derive_godot_class(input: TokenStream) -> TokenStream {
479490
translate(input, class::derive_godot_class)
480491
}
@@ -773,6 +784,15 @@ pub fn derive_godot_class(input: TokenStream) -> TokenStream {
773784
/// pub fn two(&self) { }
774785
/// }
775786
/// ```
787+
#[doc(
788+
alias = "func",
789+
alias = "rpc",
790+
alias = "virtual",
791+
alias = "signal",
792+
alias = "constant",
793+
alias = "rename",
794+
alias = "secondary"
795+
)]
776796
#[proc_macro_attribute]
777797
pub fn godot_api(meta: TokenStream, input: TokenStream) -> TokenStream {
778798
translate(input, |body| {
@@ -827,9 +847,9 @@ pub fn godot_dyn(_meta: TokenStream, input: TokenStream) -> TokenStream {
827847
translate(input, class::attribute_godot_dyn)
828848
}
829849

830-
/// Derive macro for [`GodotConvert`](../builtin/meta/trait.GodotConvert.html) on structs.
850+
/// Derive macro for [`GodotConvert`](../meta/trait.GodotConvert.html) on structs.
831851
///
832-
/// This derive macro also derives [`ToGodot`](../builtin/meta/trait.ToGodot.html) and [`FromGodot`](../builtin/meta/trait.FromGodot.html).
852+
/// This derive macro also derives [`ToGodot`](../meta/trait.ToGodot.html) and [`FromGodot`](../meta/trait.FromGodot.html).
833853
///
834854
/// # Choosing a Via type
835855
///
@@ -960,7 +980,7 @@ pub fn derive_godot_convert(input: TokenStream) -> TokenStream {
960980

961981
/// Derive macro for [`Var`](../register/property/trait.Var.html) on enums.
962982
///
963-
/// This expects a derived [`GodotConvert`](../builtin/meta/trait.GodotConvert.html) implementation, using a manual
983+
/// This expects a derived [`GodotConvert`](../meta/trait.GodotConvert.html) implementation, using a manual
964984
/// implementation of `GodotConvert` may lead to incorrect values being displayed in Godot.
965985
#[proc_macro_derive(Var, attributes(godot))]
966986
pub fn derive_var(input: TokenStream) -> TokenStream {

godot/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
//! * **`codegen-rustfmt`**
108108
//!
109109
//! Use rustfmt to format generated binding code. Because rustfmt is so slow, this is detrimental to initial compile time.
110-
//! Without it, we use a lightweight and fast custom formatter to enable basic human readability.
110+
//! Without it, we use a lightweight and fast custom formatter to enable basic human readability.<br><br>
111111
//!
112112
//! * **`register-docs`**
113113
//!

0 commit comments

Comments
 (0)