@@ -333,44 +333,60 @@ pub struct ConcreteLookAheadSelection<'a, S: 'a> {
333
333
/// `'sel` lifetime is intended to point to the data that this `LookAheadSelection` (or
334
334
/// `ConcreteLookAheadSelection`) points to.
335
335
pub trait LookAheadMethods < ' sel , S > {
336
- /// Get the (potentially aliased) name of the field represented by the current selection
336
+ /// Returns the original name of the field, represented by the current selection.
337
+ fn field_original_name ( & self ) -> & ' sel str ;
338
+
339
+ /// Returns the alias of the field, represented by the current selection, if any.
340
+ fn field_alias ( & self ) -> Option < & ' sel str > ;
341
+
342
+ /// Returns the (potentially aliased) name of the field, represented by the current selection.
337
343
fn field_name ( & self ) -> & ' sel str ;
338
344
339
- /// Get the the child selection for a given field
340
- /// If a child has an alias, it will only match if the alias matches `name`
345
+ /// Returns the child selection for the specified field.
346
+ ///
347
+ /// If a child has an alias, it will only match if the alias matches the specified `name`.
341
348
fn select_child ( & self , name : & str ) -> Option < & Self > ;
342
349
343
- /// Check if a given child selection with a name exists
344
- /// If a child has an alias, it will only match if the alias matches `name`
350
+ /// Checks if a child selection with the specified `name` exists.
351
+ ///
352
+ /// If a child has an alias, it will only match if the alias matches the specified `name`.
345
353
fn has_child ( & self , name : & str ) -> bool {
346
354
self . select_child ( name) . is_some ( )
347
355
}
348
356
349
- /// Does the current node have any arguments?
357
+ /// Indicates whether the current node has any arguments.
350
358
fn has_arguments ( & self ) -> bool ;
351
359
352
- /// Does the current node have any children?
360
+ /// Indicates whether the current node has any children.
353
361
fn has_children ( & self ) -> bool ;
354
362
355
- /// Get the top level arguments for the current selection
363
+ /// Returns the top level arguments from the current selection.
356
364
fn arguments ( & self ) -> & [ LookAheadArgument < S > ] ;
357
365
358
- /// Get the top level argument with a given name from the current selection
366
+ /// Returns the top level argument with the specified ` name` from the current selection.
359
367
fn argument ( & self , name : & str ) -> Option < & LookAheadArgument < S > > {
360
368
self . arguments ( ) . iter ( ) . find ( |a| a. name == name)
361
369
}
362
370
363
- /// Get the (possibly aliased) names of the top level children for the current selection
371
+ /// Returns the (possibly aliased) names of the top level children from the current selection.
364
372
fn child_names ( & self ) -> Vec < & ' sel str > ;
365
373
366
- /// Get an iterator over the children for the current selection
374
+ /// Returns an [`Iterator`] over the children from the current selection.
367
375
fn children ( & self ) -> Vec < & Self > ;
368
376
369
- /// Get the parent type in case there is any for this selection
377
+ /// Returns the parent type, in case there is any for the current selection.
370
378
fn applies_for ( & self ) -> Option < & str > ;
371
379
}
372
380
373
381
impl < ' a , S > LookAheadMethods < ' a , S > for ConcreteLookAheadSelection < ' a , S > {
382
+ fn field_original_name ( & self ) -> & ' a str {
383
+ self . name
384
+ }
385
+
386
+ fn field_alias ( & self ) -> Option < & ' a str > {
387
+ self . alias
388
+ }
389
+
374
390
fn field_name ( & self ) -> & ' a str {
375
391
self . alias . unwrap_or ( self . name )
376
392
}
@@ -408,6 +424,14 @@ impl<'a, S> LookAheadMethods<'a, S> for ConcreteLookAheadSelection<'a, S> {
408
424
}
409
425
410
426
impl < ' a , S > LookAheadMethods < ' a , S > for LookAheadSelection < ' a , S > {
427
+ fn field_original_name ( & self ) -> & ' a str {
428
+ self . name
429
+ }
430
+
431
+ fn field_alias ( & self ) -> Option < & ' a str > {
432
+ self . alias
433
+ }
434
+
411
435
fn field_name ( & self ) -> & ' a str {
412
436
self . alias . unwrap_or ( self . name )
413
437
}
@@ -1419,6 +1443,8 @@ query Hero {
1419
1443
)
1420
1444
. unwrap ( ) ;
1421
1445
1446
+ assert_eq ! ( look_ahead. field_original_name( ) , "hero" ) ;
1447
+ assert ! ( look_ahead. field_alias( ) . is_none( ) ) ;
1422
1448
assert_eq ! ( look_ahead. field_name( ) , "hero" ) ;
1423
1449
1424
1450
assert ! ( look_ahead. has_arguments( ) ) ;
@@ -1436,8 +1462,8 @@ query Hero {
1436
1462
let name_child = children. next ( ) . unwrap ( ) ;
1437
1463
assert ! ( look_ahead. has_child( "name" ) ) ;
1438
1464
assert_eq ! ( name_child, look_ahead. select_child( "name" ) . unwrap( ) ) ;
1439
- assert_eq ! ( name_child. name , "name" ) ;
1440
- assert_eq ! ( name_child. alias , None ) ;
1465
+ assert_eq ! ( name_child. field_original_name ( ) , "name" ) ;
1466
+ assert_eq ! ( name_child. field_alias ( ) , None ) ;
1441
1467
assert_eq ! ( name_child. field_name( ) , "name" ) ;
1442
1468
assert ! ( !name_child. has_arguments( ) ) ;
1443
1469
assert ! ( !name_child. has_children( ) ) ;
@@ -1448,17 +1474,17 @@ query Hero {
1448
1474
aliased_name_child,
1449
1475
look_ahead. select_child( "aliasedName" ) . unwrap( )
1450
1476
) ;
1451
- assert_eq ! ( aliased_name_child. name , "name" ) ;
1452
- assert_eq ! ( aliased_name_child. alias , Some ( "aliasedName" ) ) ;
1477
+ assert_eq ! ( aliased_name_child. field_original_name ( ) , "name" ) ;
1478
+ assert_eq ! ( aliased_name_child. field_alias ( ) , Some ( "aliasedName" ) ) ;
1453
1479
assert_eq ! ( aliased_name_child. field_name( ) , "aliasedName" ) ;
1454
1480
assert ! ( !aliased_name_child. has_arguments( ) ) ;
1455
1481
assert ! ( !aliased_name_child. has_children( ) ) ;
1456
1482
1457
1483
let friends_child = children. next ( ) . unwrap ( ) ;
1458
1484
assert ! ( look_ahead. has_child( "friends" ) ) ;
1459
1485
assert_eq ! ( friends_child, look_ahead. select_child( "friends" ) . unwrap( ) ) ;
1460
- assert_eq ! ( friends_child. name , "friends" ) ;
1461
- assert_eq ! ( friends_child. alias , None ) ;
1486
+ assert_eq ! ( friends_child. field_original_name ( ) , "friends" ) ;
1487
+ assert_eq ! ( friends_child. field_alias ( ) , None ) ;
1462
1488
assert_eq ! ( friends_child. field_name( ) , "friends" ) ;
1463
1489
assert ! ( !friends_child. has_arguments( ) ) ;
1464
1490
assert ! ( friends_child. has_children( ) ) ;
@@ -1470,8 +1496,8 @@ query Hero {
1470
1496
let child = friends_children. next ( ) . unwrap ( ) ;
1471
1497
assert ! ( friends_child. has_child( "name" ) ) ;
1472
1498
assert_eq ! ( child, friends_child. select_child( "name" ) . unwrap( ) ) ;
1473
- assert_eq ! ( child. name , "name" ) ;
1474
- assert_eq ! ( child. alias , None ) ;
1499
+ assert_eq ! ( child. field_original_name ( ) , "name" ) ;
1500
+ assert_eq ! ( child. field_alias ( ) , None ) ;
1475
1501
assert_eq ! ( child. field_name( ) , "name" ) ;
1476
1502
assert ! ( !child. has_arguments( ) ) ;
1477
1503
assert ! ( !child. has_children( ) ) ;
0 commit comments