@@ -15,7 +15,7 @@ pub struct FragmentDefinition {
1515#[ derive( Debug , Clone , PartialEq ) ]
1616pub struct SelectionSet {
1717 span : ( Pos , Pos ) ,
18- pub items : Vec < Selection > ,
18+ items : Vec < Selection > ,
1919}
2020
2121impl SelectionSet {
@@ -29,6 +29,28 @@ impl SelectionSet {
2929 items : Vec :: new ( ) ,
3030 }
3131 }
32+
33+ pub fn is_empty ( & self ) -> bool {
34+ self . items . is_empty ( )
35+ }
36+
37+ pub fn included ( & self ) -> impl Iterator < Item = & Selection > {
38+ self . items . iter ( ) . filter ( |selection| selection. selected ( ) )
39+ }
40+
41+ pub fn selections ( & self ) -> impl Iterator < Item = & Selection > {
42+ self . items . iter ( )
43+ }
44+
45+ pub fn push ( & mut self , field : Field ) {
46+ self . items . push ( Selection :: Field ( field) )
47+ }
48+ }
49+
50+ impl Extend < Selection > for SelectionSet {
51+ fn extend < T : IntoIterator < Item = Selection > > ( & mut self , iter : T ) {
52+ self . items . extend ( iter)
53+ }
3254}
3355
3456#[ derive( Debug , Clone , PartialEq ) ]
@@ -51,7 +73,7 @@ impl Selection {
5173 }
5274
5375 /// Returns true if a selection should be skipped (as per the `@skip` directive).
54- pub fn skip ( & self ) -> bool {
76+ fn skip ( & self ) -> bool {
5577 match self . get_directive ( "skip" ) {
5678 Some ( directive) => match directive. argument_value ( "if" ) {
5779 Some ( val) => match val {
@@ -66,7 +88,7 @@ impl Selection {
6688 }
6789
6890 /// Returns true if a selection should be included (as per the `@include` directive).
69- pub fn include ( & self ) -> bool {
91+ fn include ( & self ) -> bool {
7092 match self . get_directive ( "include" ) {
7193 Some ( directive) => match directive. argument_value ( "if" ) {
7294 Some ( val) => match val {
@@ -79,6 +101,10 @@ impl Selection {
79101 None => true ,
80102 }
81103 }
104+
105+ fn selected ( & self ) -> bool {
106+ !self . skip ( ) && self . include ( )
107+ }
82108}
83109
84110#[ derive( Debug , Clone , PartialEq ) ]
0 commit comments