@@ -22,32 +22,6 @@ pub struct Context {
22
22
pub params : Params ,
23
23
}
24
24
25
- /// A light-weight tag that denotes the [`State`] variant.
26
- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Default ) ]
27
- pub enum FetchStateTag {
28
- #[ default]
29
- Initial ,
30
- Ready ,
31
- Pending ,
32
- Failed ,
33
- }
34
-
35
- impl FetchStateTag {
36
- /// Check whether the state is stable.
37
- #[ must_use]
38
- pub const fn is_idle ( & self ) -> bool {
39
- match self {
40
- Self :: Initial | Self :: Ready | Self :: Failed => true ,
41
- Self :: Pending => false ,
42
- }
43
- }
44
-
45
- #[ must_use]
46
- pub const fn should_prefetch ( & self ) -> bool {
47
- matches ! ( self , Self :: Initial )
48
- }
49
- }
50
-
51
25
#[ derive( Debug , Clone ) ]
52
26
pub struct FetchedEntity {
53
27
pub offset_hash : u64 ,
@@ -85,20 +59,13 @@ enum FetchState {
85
59
86
60
impl FetchState {
87
61
#[ must_use]
88
- const fn state_tag ( & self ) -> FetchStateTag {
62
+ const fn is_idle ( & self ) -> bool {
89
63
match self {
90
- Self :: Initial => FetchStateTag :: Initial ,
91
- Self :: Ready { .. } => FetchStateTag :: Ready ,
92
- Self :: Failed { .. } => FetchStateTag :: Failed ,
93
- Self :: Pending { .. } => FetchStateTag :: Pending ,
64
+ Self :: Initial | Self :: Ready { .. } | Self :: Failed { .. } => true ,
65
+ Self :: Pending { .. } => false ,
94
66
}
95
67
}
96
68
97
- #[ must_use]
98
- const fn is_idle ( & self ) -> bool {
99
- self . state_tag ( ) . is_idle ( )
100
- }
101
-
102
69
#[ must_use]
103
70
fn fetched_entities ( & self ) -> Option < & [ FetchedEntity ] > {
104
71
match self {
@@ -119,7 +86,7 @@ impl FetchState {
119
86
120
87
#[ must_use]
121
88
const fn should_prefetch ( & self ) -> bool {
122
- self . state_tag ( ) . should_prefetch ( )
89
+ matches ! ( self , Self :: Initial )
123
90
}
124
91
125
92
#[ must_use]
@@ -272,11 +239,6 @@ impl State {
272
239
& self . context
273
240
}
274
241
275
- #[ must_use]
276
- pub const fn fetch_state_tag ( & self ) -> FetchStateTag {
277
- self . fetch . state_tag ( )
278
- }
279
-
280
242
#[ must_use]
281
243
pub const fn is_idle ( & self ) -> bool {
282
244
self . fetch . is_idle ( )
@@ -314,7 +276,8 @@ impl State {
314
276
// is required to avoid redundant code for determining in advance if
315
277
// the state would actually change or not.
316
278
let reset = Self :: new ( self . default_params . clone ( ) ) ;
317
- if self . context == reset. context && self . fetch . state_tag ( ) == reset. fetch . state_tag ( ) {
279
+ if self . context == reset. context && matches ! ( self . fetch, FetchState :: Initial ) {
280
+ debug_assert ! ( matches!( reset. fetch, FetchState :: Initial ) ) ;
318
281
// No effect.
319
282
log:: debug!( "State doesn't need to be reset" ) ;
320
283
return false ;
0 commit comments