@@ -11,7 +11,7 @@ use std::collections::HashSet;
1111/// - attributes slice
1212/// - manually feeding values into the underlying contexts
1313///
14- /// Query this context to know if you need skip a block.
14+ /// Query this context to know if you need to skip a block.
1515#[ derive( Default , Clone ) ]
1616pub ( crate ) struct SkipContext {
1717 pub ( crate ) macros : SkipNameContext ,
@@ -20,8 +20,8 @@ pub(crate) struct SkipContext {
2020
2121impl SkipContext {
2222 pub ( crate ) fn update_with_attrs ( & mut self , attrs : & [ ast:: Attribute ] ) {
23- self . macros . append ( get_skip_names ( "macros" , attrs) ) ;
24- self . attributes . append ( get_skip_names ( "attributes" , attrs) ) ;
23+ self . macros . extend ( get_skip_names ( "macros" , attrs) ) ;
24+ self . attributes . extend ( get_skip_names ( "attributes" , attrs) ) ;
2525 }
2626
2727 pub ( crate ) fn update ( & mut self , other : SkipContext ) {
@@ -34,28 +34,52 @@ impl SkipContext {
3434/// Track which names to skip.
3535///
3636/// Query this context with a string to know whether to skip it.
37- #[ derive( Default , Clone ) ]
38- pub ( crate ) struct SkipNameContext {
39- all : bool ,
40- values : HashSet < String > ,
37+ #[ derive( Clone ) ]
38+ pub ( crate ) enum SkipNameContext {
39+ All ,
40+ Values ( HashSet < String > ) ,
4141}
4242
43- impl SkipNameContext {
44- pub ( crate ) fn append ( & mut self , values : Vec < String > ) {
45- self . values . extend ( values) ;
43+ impl Default for SkipNameContext {
44+ fn default ( ) -> Self {
45+ Self :: Values ( Default :: default ( ) )
46+ }
47+ }
48+
49+ impl Extend < String > for SkipNameContext {
50+ fn extend < T : IntoIterator < Item = String > > ( & mut self , iter : T ) {
51+ match self {
52+ Self :: All => { }
53+ Self :: Values ( values) => values. extend ( iter) ,
54+ }
4655 }
56+ }
4757
58+ impl SkipNameContext {
4859 pub ( crate ) fn update ( & mut self , other : Self ) {
49- self . all = self . all || other. all ;
50- self . values . extend ( other. values ) ;
60+ match ( self , other) {
61+ // If we're already skipping everything, nothing more can be added
62+ ( Self :: All , _) => { }
63+ // If we want to skip all, set it
64+ ( this, Self :: All ) => {
65+ * this = Self :: All ;
66+ }
67+ // If we have some new values to skip, add them
68+ ( Self :: Values ( existing_values) , Self :: Values ( new_values) ) => {
69+ existing_values. extend ( new_values)
70+ }
71+ }
5172 }
5273
5374 pub ( crate ) fn skip ( & self , name : & str ) -> bool {
54- self . all || self . values . contains ( name)
75+ match self {
76+ Self :: All => true ,
77+ Self :: Values ( values) => values. contains ( name) ,
78+ }
5579 }
5680
57- pub ( crate ) fn set_all ( & mut self , all : bool ) {
58- self . all = all ;
81+ pub ( crate ) fn skip_all ( & mut self ) {
82+ * self = Self :: All ;
5983 }
6084}
6185
0 commit comments