@@ -327,14 +327,12 @@ pub struct TreeMapMutRevIterator<'a, K, V> {
327
327
// other macros, so this takes the `& <mutability> <operand>` token
328
328
// sequence and forces their evalutation as an expression.
329
329
macro_rules! addr { ( $e: expr) => { $e } }
330
+ // putting an optional mut into type signatures
331
+ macro_rules! item { ( $i: item) => { $i } }
330
332
331
333
macro_rules! define_iterator {
332
334
( $name: ident,
333
335
$rev_name: ident,
334
- // the type of the values of the treemap in the return value of
335
- // the iterator (i.e. &V or &mut V). This is non-hygienic in the
336
- // name of the lifetime.
337
- value_type = $value_type: ty,
338
336
339
337
// the function to go from &m Option<~TreeNode> to *m TreeNode
340
338
deref = $deref: ident,
@@ -343,10 +341,11 @@ macro_rules! define_iterator {
343
341
// there's no support for 0-or-1 repeats.
344
342
addr_mut = $( $addr_mut: tt) *
345
343
) => {
346
- // private methods on the forward iterator
347
- impl <' a, K , V > $name<' a, K , V > {
344
+ // private methods on the forward iterator (item!() for the
345
+ // addr_mut in the next_ return value)
346
+ item!( impl <' a, K , V > $name<' a, K , V > {
348
347
#[ inline( always) ]
349
- fn next_( & mut self , forward: bool ) -> Option <( & ' a K , $value_type ) > {
348
+ fn next_( & mut self , forward: bool ) -> Option <( & ' a K , & ' a $ ( $addr_mut ) * V ) > {
350
349
while !self . stack. is_empty( ) || !self . node. is_null( ) {
351
350
if !self . node. is_null( ) {
352
351
let node = unsafe { addr!( & $( $addr_mut) * * self . node) } ;
@@ -412,41 +411,40 @@ macro_rules! define_iterator {
412
411
self . node = ptr:: RawPtr :: null( ) ;
413
412
}
414
413
}
415
- }
414
+ } )
416
415
417
416
// the forward Iterator impl.
418
- impl <' a, K , V > Iterator <( & ' a K , $value_type ) > for $name<' a, K , V > {
417
+ item! ( impl <' a, K , V > Iterator <( & ' a K , & ' a $ ( $addr_mut ) * V ) > for $name<' a, K , V > {
419
418
/// Advance the iterator to the next node (in order) and return a
420
419
/// tuple with a reference to the key and value. If there are no
421
420
/// more nodes, return `None`.
422
- fn next( & mut self ) -> Option <( & ' a K , $value_type ) > {
421
+ fn next( & mut self ) -> Option <( & ' a K , & ' a $ ( $addr_mut ) * V ) > {
423
422
self . next_( true )
424
423
}
425
424
426
425
#[ inline]
427
426
fn size_hint( & self ) -> ( uint, Option <uint>) {
428
427
( self . remaining_min, Some ( self . remaining_max) )
429
428
}
430
- }
429
+ } )
431
430
432
431
// the reverse Iterator impl.
433
- impl <' a, K , V > Iterator <( & ' a K , $value_type ) > for $rev_name<' a, K , V > {
434
- fn next( & mut self ) -> Option <( & ' a K , $value_type ) > {
432
+ item! ( impl <' a, K , V > Iterator <( & ' a K , & ' a $ ( $addr_mut ) * V ) > for $rev_name<' a, K , V > {
433
+ fn next( & mut self ) -> Option <( & ' a K , & ' a $ ( $addr_mut ) * V ) > {
435
434
self . iter. next_( false )
436
435
}
437
436
438
437
#[ inline]
439
438
fn size_hint( & self ) -> ( uint, Option <uint>) {
440
439
self . iter. size_hint( )
441
440
}
442
- }
441
+ } )
443
442
}
444
443
} // end of define_iterator
445
444
446
445
define_iterator ! {
447
446
TreeMapIterator ,
448
447
TreeMapRevIterator ,
449
- value_type = & ' a V ,
450
448
deref = deref,
451
449
452
450
// immutable, so no mut
@@ -455,7 +453,6 @@ define_iterator! {
455
453
define_iterator ! {
456
454
TreeMapMutIterator ,
457
455
TreeMapMutRevIterator ,
458
- value_type = & ' a mut V ,
459
456
deref = mut_deref,
460
457
461
458
addr_mut = mut
0 commit comments