@@ -212,14 +212,14 @@ impl<C: NativeClass, F: StaticArgsMethod<C>> Method<C> for StaticArgs<F> {
212
212
/// for common operations with them. Can also be used as an iterator.
213
213
pub struct Varargs < ' a > {
214
214
idx : usize ,
215
- iter : std :: slice :: Iter < ' a , & ' a Variant > ,
215
+ args : & ' a [ & ' a Variant ] ,
216
216
}
217
217
218
218
impl < ' a > Varargs < ' a > {
219
219
/// Returns the amount of arguments left.
220
220
#[ inline]
221
221
pub fn len ( & self ) -> usize {
222
- self . iter . len ( )
222
+ self . args . len ( ) - self . idx
223
223
}
224
224
225
225
#[ inline]
@@ -250,7 +250,7 @@ impl<'a> Varargs<'a> {
250
250
/// Returns the remaining arguments as a slice of `Variant`s.
251
251
#[ inline]
252
252
pub fn as_slice ( & self ) -> & ' a [ & ' a Variant ] {
253
- self . iter . as_slice ( )
253
+ self . args
254
254
}
255
255
256
256
/// Discard the rest of the arguments, and return an error if there is any.
@@ -282,18 +282,21 @@ impl<'a> Varargs<'a> {
282
282
pub unsafe fn from_sys ( num_args : libc:: c_int , args : * mut * mut sys:: godot_variant ) -> Self {
283
283
let args = std:: slice:: from_raw_parts ( args, num_args as usize ) ;
284
284
let args = std:: mem:: transmute :: < & [ * mut sys:: godot_variant ] , & [ & Variant ] > ( args) ;
285
- Self {
286
- idx : 0 ,
287
- iter : args. iter ( ) ,
288
- }
285
+ Self { idx : 0 , args }
289
286
}
290
287
}
291
288
292
289
impl < ' a > Iterator for Varargs < ' a > {
293
290
type Item = & ' a Variant ;
294
291
#[ inline]
295
292
fn next ( & mut self ) -> Option < Self :: Item > {
296
- self . iter . next ( ) . copied ( )
293
+ if self . idx < self . args . len ( ) {
294
+ let idx = self . idx ;
295
+ self . idx += 1 ;
296
+ Some ( self . args [ idx] )
297
+ } else {
298
+ None
299
+ }
297
300
}
298
301
}
299
302
@@ -391,8 +394,7 @@ impl<'r, 'a, T: FromVariant> ArgBuilder<'r, 'a, T> {
391
394
} = self ;
392
395
let idx = args. idx ;
393
396
394
- if let Some ( arg) = args. iter . next ( ) {
395
- args. idx += 1 ;
397
+ if let Some ( arg) = args. next ( ) {
396
398
T :: from_variant ( arg) . map ( Some ) . map_err ( |err| ArgumentError {
397
399
site : * site,
398
400
kind : ArgumentErrorKind :: CannotConvert {
0 commit comments