diff --git a/src/error.rs b/src/error.rs index 4863924..ad46530 100644 --- a/src/error.rs +++ b/src/error.rs @@ -29,3 +29,13 @@ pub async fn async_result_context < Err (error) => on_failure (error) , } ; } + +pub async fn async_unit_result_context < + AsyncFunction : Future < Output = Result <()> > , + FailureHandler : Fn (ZoodexError) , +> ( + function : AsyncFunction , + on_failure : FailureHandler , +) { + async_result_context ( function , |_| () , on_failure ) . await ; +} diff --git a/src/main.rs b/src/main.rs index 537f1ec..6039b6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,17 +26,20 @@ fn on_activate ( app : & Application ) { ui . show_window () ; spawn_future_local ( async move { - async_result_context ( async { - let collection = spawn_blocking ( || read_collection_file () ) - . await ? ? ; - ui . render_collection (collection) ; + async_unit_result_context ( + async { + let collection = spawn_blocking ( || + get_collection_from_file () ) . await ? ? ; + ui . render_collection (collection) ; - Ok (()) - } , |_| () , |error| { - match error { - CollectionFileError => eprintln ! ("Could not open collection file") , - } ; - ui . close_window () ; - } ) . await ; + Ok (()) + } , + |error| { + match error { + CollectionFileError => eprintln ! ("Could not open collection file") , + } ; + ui . close_window () ; + } , + ) . await ; } ) ; } diff --git a/src/persistence.rs b/src/persistence.rs index 6858d43..e7c8e6d 100644 --- a/src/persistence.rs +++ b/src/persistence.rs @@ -8,7 +8,7 @@ use crate :: { collection :: * , error :: { * , ZoodexError :: * } } ; -pub fn read_collection_file () -> Result { +pub fn get_collection_from_file () -> Result { let sqlite_connection = Connection :: open ("zoodex.sqlite") ? ; let mut films_query = sqlite_connection