Skip to content

Commit 32f0efc

Browse files
bors[bot]Cankyre
andauthored
Merge #276
276: Added doc aliases for godot-core/builtin r=Bromeon a=Cankyre Solved Issue #232 by adding doc-aliases to methods that differ from [Godot's Docs](https://docs.godotengine.org/en/stable/classes/index.html#variant-types) in folder `godot-core/src/builtin`. I might have forgotten some in the Vectors section, whose code needs to be better documented. Co-authored-by: Cankyre <[email protected]>
2 parents d4c35c6 + ff10431 commit 32f0efc

File tree

9 files changed

+25
-9
lines changed

9 files changed

+25
-9
lines changed

godot-core/src/builtin/aabb.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,13 @@ impl Aabb {
5252
}
5353

5454
/// Set size based on desired end-point.
55-
///
56-
/// _Godot equivalent: `Aabb.size` property_
5755
#[inline]
5856
pub fn set_end(&mut self, end: Vector3) {
5957
self.size = end - self.position
6058
}
6159

6260
/// Returns `true` if the two `Aabb`s are approximately equal, by calling `is_equal_approx` on
6361
/// `position` and `size`.
64-
///
65-
/// _Godot equivalent: `Aabb.is_equal_approx()`_
6662
#[inline]
6763
pub fn is_equal_approx(&self, other: &Self) -> bool {
6864
self.position.is_equal_approx(other.position) && self.size.is_equal_approx(other.size)

godot-core/src/builtin/array.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ use sys::{ffi_methods, interface_fn, GodotFfi};
4242
/// Usage is safe if the `Array` is used on a single thread only. Concurrent reads on
4343
/// different threads are also safe, but any writes must be externally synchronized. The Rust
4444
/// compiler will enforce this as long as you use only Rust threads, but it cannot protect against
45+
4546
/// concurrent modification on other threads (e.g. created through GDScript).
47+
4648
// `T` must be restricted to `VariantMetadata` in the type, because `Drop` can only be implemented
4749
// for `T: VariantMetadata` because `drop()` requires `sys_mut()`, which is on the `GodotFfi`
4850
// trait, whose `from_sys_init()` requires `Default`, which is only implemented for `T:
@@ -82,6 +84,7 @@ impl<T: VariantMetadata> Array<T> {
8284
///
8385
/// Retrieving the size incurs an FFI call. If you know the size hasn't changed, you may consider storing
8486
/// it in a variable. For loops, prefer iterators.
87+
#[doc(alias = "size")]
8588
pub fn len(&self) -> usize {
8689
to_usize(self.as_inner().size())
8790
}

godot-core/src/builtin/basis.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ impl Basis {
145145
///
146146
#[cfg(gdextension_api = "4.0")]
147147
/// _Godot equivalent: `Basis.looking_at()`_
148+
#[doc(alias = "looking_at")]
148149
pub fn new_looking_at(target: Vector3, up: Vector3) -> Self {
149150
super::inner::InnerBasis::looking_at(target, up)
150151
}
@@ -165,7 +166,8 @@ impl Basis {
165166

166167
/// Creates a [`Quaternion`] representing the same rotation as this basis.
167168
///
168-
/// _Godot equivalent: `Basis()`_
169+
/// _Godot equivalent: `Basis.get_rotation_quaternion()`_
170+
#[doc(alias = "get_rotation_quaternion")]
169171
pub fn to_quat(self) -> Quaternion {
170172
RQuat::from_mat3(&self.orthonormalized().to_glam()).to_front()
171173
}
@@ -459,6 +461,7 @@ impl Basis {
459461
/// Returns the first column of the matrix,
460462
///
461463
/// _Godot equivalent: `Basis.x`_
464+
#[doc(alias = "x")]
462465
#[must_use]
463466
pub fn col_a(&self) -> Vector3 {
464467
Vector3::new(self.rows[0].x, self.rows[1].x, self.rows[2].x)
@@ -474,6 +477,7 @@ impl Basis {
474477
/// Returns the second column of the matrix,
475478
///
476479
/// _Godot equivalent: `Basis.y`_
480+
#[doc(alias = "y")]
477481
#[must_use]
478482
pub fn col_b(&self) -> Vector3 {
479483
Vector3::new(self.rows[0].y, self.rows[1].y, self.rows[2].y)
@@ -489,6 +493,7 @@ impl Basis {
489493
/// Returns the third column of the matrix,
490494
///
491495
/// _Godot equivalent: `Basis.z`_
496+
#[doc(alias = "z")]
492497
#[must_use]
493498
pub fn col_c(&self) -> Vector3 {
494499
Vector3::new(self.rows[0].z, self.rows[1].z, self.rows[2].z)

godot-core/src/builtin/dictionary.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl Dictionary {
7474
/// the key if the key was in the dictionary.
7575
///
7676
/// _Godot equivalent: `erase`_
77+
#[doc(alias = "erase")]
7778
pub fn remove<K: ToVariant>(&mut self, key: K) -> Option<Variant> {
7879
let key = key.to_variant();
7980
let old_value = self.get(key.clone());
@@ -89,6 +90,7 @@ impl Dictionary {
8990
/// using a `HashMap` or `Dictionary` with the inverse mapping (`V` -> `K`).
9091
///
9192
/// _Godot equivalent: `find_key`_
93+
#[doc(alias = "find_key")]
9294
pub fn find_key_by_value<V: ToVariant>(&self, value: V) -> Option<Variant> {
9395
let key = self.as_inner().find_key(value.to_variant());
9496

@@ -118,13 +120,15 @@ impl Dictionary {
118120
/// If you need that, use [`Self::get`].
119121
///
120122
/// _Godot equivalent: `dict.get(key, null)`_
123+
#[doc(alias = "get")]
121124
pub fn get_or_nil<K: ToVariant>(&self, key: K) -> Variant {
122125
self.as_inner().get(key.to_variant(), Variant::nil())
123126
}
124127

125128
/// Returns `true` if the dictionary contains the given key.
126129
///
127130
/// _Godot equivalent: `has`_
131+
#[doc(alias = "has")]
128132
pub fn contains_key<K: ToVariant>(&self, key: K) -> bool {
129133
let key = key.to_variant();
130134
self.as_inner().has(key)
@@ -133,6 +137,7 @@ impl Dictionary {
133137
/// Returns `true` if the dictionary contains all the given keys.
134138
///
135139
/// _Godot equivalent: `has_all`_
140+
#[doc(alias = "has_all")]
136141
pub fn contains_all_keys(&self, keys: VariantArray) -> bool {
137142
self.as_inner().has_all(keys)
138143
}
@@ -145,13 +150,15 @@ impl Dictionary {
145150
/// Creates a new `Array` containing all the keys currently in the dictionary.
146151
///
147152
/// _Godot equivalent: `keys`_
153+
#[doc(alias = "keys")]
148154
pub fn keys_array(&self) -> VariantArray {
149155
self.as_inner().keys()
150156
}
151157

152158
/// Creates a new `Array` containing all the values currently in the dictionary.
153159
///
154160
/// _Godot equivalent: `values`_
161+
#[doc(alias = "values")]
155162
pub fn values_array(&self) -> VariantArray {
156163
self.as_inner().values()
157164
}
@@ -166,13 +173,15 @@ impl Dictionary {
166173
/// If `overwrite` is true, it will overwrite pre-existing keys.
167174
///
168175
/// _Godot equivalent: `merge`_
176+
#[doc(alias = "merge")]
169177
pub fn extend_dictionary(&mut self, other: Self, overwrite: bool) {
170178
self.as_inner().merge(other, overwrite)
171179
}
172180

173181
/// Returns the number of entries in the dictionary.
174182
///
175183
/// This is equivalent to `size` in Godot.
184+
#[doc(alias = "size")]
176185
pub fn len(&self) -> usize {
177186
self.as_inner().size().try_into().unwrap()
178187
}

godot-core/src/builtin/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ mod real_mod {
161161
/// [`f64`], see [`RealConv`](super::RealConv).
162162
///
163163
/// See also the [Godot docs on float](https://docs.godotengine.org/en/stable/classes/class_float.html).
164-
///
165-
/// _Godot equivalent: `real_t`_
166164
// As this is a scalar value, we will use a non-standard type name.
167165
#[allow(non_camel_case_types)]
168166
pub type real = f32;
@@ -327,6 +325,7 @@ macro_rules! real {
327325
/// The side of a [`Rect2`] or [`Rect2i`].
328326
///
329327
/// _Godot equivalent: `@GlobalScope.Side`_
328+
#[doc(alias = "Side")]
330329
#[derive(Copy, Clone)]
331330
#[repr(C)]
332331
pub enum RectSide {

godot-core/src/builtin/packed_array.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ macro_rules! impl_packed_array {
201201

202202
/// Appends an element to the end of the array. Equivalent of `append` and `push_back`
203203
/// in GDScript.
204+
#[doc(alias = "append")]
205+
#[doc(alias = "push_back")]
204206
pub fn push(&mut self, value: $Element) {
205207
self.as_inner().push_back(Self::into_arg(value));
206208
}
@@ -231,6 +233,7 @@ macro_rules! impl_packed_array {
231233
// Design note: This returns the removed value instead of `()` for consistency with
232234
// `Array` and with `Vec::remove`. Compared to shifting all the subsequent array
233235
// elements to their new position, the overhead of retrieving this element is trivial.
236+
#[doc(alias = "remove_at")]
234237
pub fn remove(&mut self, index: usize) -> $Element {
235238
self.check_bounds(index);
236239
let element = self.get(index);

godot-core/src/builtin/rect2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ impl Rect2 {
6868
/// The end of the `Rect2` calculated as `position + size`.
6969
///
7070
/// _Godot equivalent: `Rect2.size` property_
71+
#[doc(alias = "size")]
7172
#[inline]
7273
pub fn end(&self) -> Vector2 {
7374
self.position + self.size

godot-core/src/builtin/rect2i.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ impl Rect2i {
6868
/// The end of the `Rect2i` calculated as `position + size`.
6969
///
7070
/// _Godot equivalent: `Rect2i.size` property_
71+
#[doc(alias = "size")]
7172
#[inline]
7273
pub const fn end(&self) -> Vector2i {
7374
Vector2i::new(self.position.x + self.size.x, self.position.y + self.size.y)
@@ -120,7 +121,6 @@ impl Rect2i {
120121
/// Returns the area of the `Rect2i`.
121122
///
122123
/// _Godot equivalent: `Rect2i.get_area` function_
123-
#[doc(alias = "get_area")]
124124
#[inline]
125125
pub const fn area(&self) -> i32 {
126126
self.size.x * self.size.y
@@ -131,7 +131,6 @@ impl Rect2i {
131131
/// If `size` is an odd number, the returned center value will be rounded towards `position`.
132132
///
133133
/// _Godot equivalent: `Rect2i.get_center` function_
134-
#[doc(alias = "get_center")]
135134
#[inline]
136135
pub fn center(&self) -> Vector2i {
137136
self.position + (self.size / 2)

godot-core/src/builtin/rid.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ impl Rid {
5252
/// Convert this RID into a [`u64`]. Returns 0 if it is invalid.
5353
///
5454
/// _Godot equivalent: `Rid.get_id()`_
55+
#[doc(alias = "get_id")]
5556
#[inline]
5657
pub const fn to_u64(self) -> u64 {
5758
match self {

0 commit comments

Comments
 (0)