@@ -133,6 +133,11 @@ impl<T: ArrayElement> Array<T> {
133
133
}
134
134
}
135
135
136
+ #[ deprecated = "Renamed to `get`." ]
137
+ pub fn try_get ( & self , index : usize ) -> Option < T > {
138
+ self . get ( index)
139
+ }
140
+
136
141
/// Returns `true` if the array contains the given value. Equivalent of `has` in GDScript.
137
142
pub fn contains ( & self , value : & T ) -> bool {
138
143
self . as_inner ( ) . has ( value. to_variant ( ) )
@@ -172,27 +177,33 @@ impl<T: ArrayElement> Array<T> {
172
177
}
173
178
174
179
/// Returns the first element in the array, or `None` if the array is empty.
175
- ///
176
- /// Equivalent of `front()` in GDScript.
177
- #[ doc( alias = "front" ) ]
178
- pub fn first ( & self ) -> Option < T > {
180
+ #[ doc( alias = "first" ) ]
181
+ pub fn front ( & self ) -> Option < T > {
179
182
( !self . is_empty ( ) ) . then ( || {
180
183
let variant = self . as_inner ( ) . front ( ) ;
181
184
T :: from_variant ( & variant)
182
185
} )
183
186
}
184
187
185
188
/// Returns the last element in the array, or `None` if the array is empty.
186
- ///
187
- /// Equivalent of `back()` in GDScript.
188
- #[ doc( alias = "back" ) ]
189
- pub fn last ( & self ) -> Option < T > {
189
+ #[ doc( alias = "last" ) ]
190
+ pub fn back ( & self ) -> Option < T > {
190
191
( !self . is_empty ( ) ) . then ( || {
191
192
let variant = self . as_inner ( ) . back ( ) ;
192
193
T :: from_variant ( & variant)
193
194
} )
194
195
}
195
196
197
+ #[ deprecated = "Renamed to `front`, in line with GDScript method and consistent with `push_front` and `pop_front`." ]
198
+ pub fn first ( & self ) -> Option < T > {
199
+ self . front ( )
200
+ }
201
+
202
+ #[ deprecated = "Renamed to `back`, in line with GDScript method." ]
203
+ pub fn last ( & self ) -> Option < T > {
204
+ self . back ( )
205
+ }
206
+
196
207
/// Clears the array, removing all elements.
197
208
pub fn clear ( & mut self ) {
198
209
// SAFETY: No new values are written to the array, we only remove values from the array.
@@ -223,7 +234,7 @@ impl<T: ArrayElement> Array<T> {
223
234
unsafe { self . as_inner_mut ( ) } . push_back ( value. to_variant ( ) ) ;
224
235
}
225
236
226
- /// Adds an element at the beginning of the array, in O(n) time .
237
+ /// Adds an element at the beginning of the array, in O(n).
227
238
///
228
239
/// On large arrays, this method is much slower than [`push()`][Self::push], as it will move all the array's elements.
229
240
/// The larger the array, the slower `push_front()` will be.
@@ -243,7 +254,7 @@ impl<T: ArrayElement> Array<T> {
243
254
} )
244
255
}
245
256
246
- /// Removes and returns the first element of the array. Returns `None` if the array is empty.
257
+ /// Removes and returns the first element of the array, in O(n) . Returns `None` if the array is empty.
247
258
///
248
259
/// Note: On large arrays, this method is much slower than `pop()` as it will move all the
249
260
/// array's elements. The larger the array, the slower `pop_front()` will be.
0 commit comments