@@ -333,44 +333,60 @@ pub struct ConcreteLookAheadSelection<'a, S: 'a> {
333333/// `'sel` lifetime is intended to point to the data that this `LookAheadSelection` (or
334334/// `ConcreteLookAheadSelection`) points to.
335335pub 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.
337343 fn field_name ( & self ) -> & ' sel str ;
338344
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`.
341348 fn select_child ( & self , name : & str ) -> Option < & Self > ;
342349
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`.
345353 fn has_child ( & self , name : & str ) -> bool {
346354 self . select_child ( name) . is_some ( )
347355 }
348356
349- /// Does the current node have any arguments?
357+ /// Indicates whether the current node has any arguments.
350358 fn has_arguments ( & self ) -> bool ;
351359
352- /// Does the current node have any children?
360+ /// Indicates whether the current node has any children.
353361 fn has_children ( & self ) -> bool ;
354362
355- /// Get the top level arguments for the current selection
363+ /// Returns the top level arguments from the current selection.
356364 fn arguments ( & self ) -> & [ LookAheadArgument < S > ] ;
357365
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.
359367 fn argument ( & self , name : & str ) -> Option < & LookAheadArgument < S > > {
360368 self . arguments ( ) . iter ( ) . find ( |a| a. name == name)
361369 }
362370
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.
364372 fn child_names ( & self ) -> Vec < & ' sel str > ;
365373
366- /// Get an iterator over the children for the current selection
374+ /// Returns an [`Iterator`] over the children from the current selection.
367375 fn children ( & self ) -> Vec < & Self > ;
368376
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.
370378 fn applies_for ( & self ) -> Option < & str > ;
371379}
372380
373381impl < ' 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+
374390 fn field_name ( & self ) -> & ' a str {
375391 self . alias . unwrap_or ( self . name )
376392 }
@@ -408,6 +424,14 @@ impl<'a, S> LookAheadMethods<'a, S> for ConcreteLookAheadSelection<'a, S> {
408424}
409425
410426impl < ' 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+
411435 fn field_name ( & self ) -> & ' a str {
412436 self . alias . unwrap_or ( self . name )
413437 }
@@ -1419,6 +1443,8 @@ query Hero {
14191443 )
14201444 . unwrap ( ) ;
14211445
1446+ assert_eq ! ( look_ahead. field_original_name( ) , "hero" ) ;
1447+ assert ! ( look_ahead. field_alias( ) . is_none( ) ) ;
14221448 assert_eq ! ( look_ahead. field_name( ) , "hero" ) ;
14231449
14241450 assert ! ( look_ahead. has_arguments( ) ) ;
@@ -1436,8 +1462,8 @@ query Hero {
14361462 let name_child = children. next ( ) . unwrap ( ) ;
14371463 assert ! ( look_ahead. has_child( "name" ) ) ;
14381464 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 ) ;
14411467 assert_eq ! ( name_child. field_name( ) , "name" ) ;
14421468 assert ! ( !name_child. has_arguments( ) ) ;
14431469 assert ! ( !name_child. has_children( ) ) ;
@@ -1448,17 +1474,17 @@ query Hero {
14481474 aliased_name_child,
14491475 look_ahead. select_child( "aliasedName" ) . unwrap( )
14501476 ) ;
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" ) ) ;
14531479 assert_eq ! ( aliased_name_child. field_name( ) , "aliasedName" ) ;
14541480 assert ! ( !aliased_name_child. has_arguments( ) ) ;
14551481 assert ! ( !aliased_name_child. has_children( ) ) ;
14561482
14571483 let friends_child = children. next ( ) . unwrap ( ) ;
14581484 assert ! ( look_ahead. has_child( "friends" ) ) ;
14591485 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 ) ;
14621488 assert_eq ! ( friends_child. field_name( ) , "friends" ) ;
14631489 assert ! ( !friends_child. has_arguments( ) ) ;
14641490 assert ! ( friends_child. has_children( ) ) ;
@@ -1470,8 +1496,8 @@ query Hero {
14701496 let child = friends_children. next ( ) . unwrap ( ) ;
14711497 assert ! ( friends_child. has_child( "name" ) ) ;
14721498 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 ) ;
14751501 assert_eq ! ( child. field_name( ) , "name" ) ;
14761502 assert ! ( !child. has_arguments( ) ) ;
14771503 assert ! ( !child. has_children( ) ) ;
0 commit comments