File tree 1 file changed +31
-0
lines changed
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,37 @@ pub enum DataState<T, E: ErrorBounds = anyhow::Error> {
54
54
}
55
55
56
56
impl < T , E : ErrorBounds > DataState < T , E > {
57
+ #[ cfg( feature = "egui" ) ]
58
+ /// Calls [Self::start_request] and adds a spinner if progress can be made
59
+ #[ must_use]
60
+ pub fn egui_start_request < F > ( & mut self , ui : & mut egui:: Ui , fetch_fn : F ) -> CanMakeProgress
61
+ where
62
+ F : FnOnce ( ) -> Awaiting < T , E > ,
63
+ {
64
+ let result = self . start_request ( fetch_fn) ;
65
+ if result. is_able_to_make_progress ( ) {
66
+ ui. spinner ( ) ;
67
+ }
68
+ result
69
+ }
70
+
71
+ /// Starts a new request. Only intended to be on [Self::None] and if state
72
+ /// is any other value it returns
73
+ /// [CanMakeProgress::UnableToMakeProgress]
74
+ #[ must_use]
75
+ pub fn start_request < F > ( & mut self , fetch_fn : F ) -> CanMakeProgress
76
+ where
77
+ F : FnOnce ( ) -> Awaiting < T , E > ,
78
+ {
79
+ if self . is_none ( ) {
80
+ let result = self . get ( fetch_fn) ;
81
+ assert ! ( result. is_able_to_make_progress( ) ) ;
82
+ result
83
+ } else {
84
+ CanMakeProgress :: UnableToMakeProgress
85
+ }
86
+ }
87
+
57
88
#[ cfg( feature = "egui" ) ]
58
89
/// Attempts to load the data and displays appropriate UI if applicable.
59
90
/// Some branches lead to no UI being displayed, in particular when the data
You can’t perform that action at this time.
0 commit comments