From 4fef94a5c5ff0e0ba3663c38c09a9a4431925262 Mon Sep 17 00:00:00 2001 From: Alain Emilia Anna Zscheile Date: Thu, 3 Oct 2024 13:49:33 +0200 Subject: [PATCH] egui: get rid of overabstraction file_handler::push_file_to_read --- src/bin/topola-egui/file_handler.rs | 14 +------------- src/bin/topola-egui/menu_bar.rs | 12 +++++------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/bin/topola-egui/file_handler.rs b/src/bin/topola-egui/file_handler.rs index c196875..80ef52d 100644 --- a/src/bin/topola-egui/file_handler.rs +++ b/src/bin/topola-egui/file_handler.rs @@ -46,19 +46,7 @@ impl io::BufRead for FileHandlerData { fhd_forward!(fn consume(&mut self, amt: usize)); } -#[inline] -pub async fn push_file_to_read( - file_handle: &rfd::FileHandle, - sender: Sender>, - callback: C, -) where - E: From, - C: FnOnce(FileHandlerData) -> Result, -{ - let _ = sender.send(handle_text(&file_handle, callback).await); -} - -async fn handle_text(file_handle: &rfd::FileHandle, callback: C) -> Result +pub async fn handle_file(file_handle: &rfd::FileHandle, callback: C) -> Result where E: From, C: FnOnce(FileHandlerData) -> Result, diff --git a/src/bin/topola-egui/menu_bar.rs b/src/bin/topola-egui/menu_bar.rs index a48ae05..acaa069 100644 --- a/src/bin/topola-egui/menu_bar.rs +++ b/src/bin/topola-egui/menu_bar.rs @@ -22,7 +22,7 @@ use crate::{ action::{Action, Switch, Trigger}, activity::{ActivityStatus, ActivityStepperWithStatus}, app::execute, - file_handler::{push_file_to_read, FileHandlerData}, + file_handler::{handle_file, FileHandlerData}, overlay::Overlay, translator::Translator, viewport::Viewport, @@ -243,10 +243,9 @@ impl MenuBar { execute(async move { if let Some(file_handle) = task.await { - push_file_to_read(&file_handle, content_sender, |data| { + content_sender.send(handle_file(&file_handle, |data| { SpecctraDesign::load(data) - }) - .await; + }).await); ctx.request_repaint(); } }); @@ -285,14 +284,13 @@ impl MenuBar { execute(async move { if let Some(file_handle) = task.await { - push_file_to_read(&file_handle, history_sender, |data| { + history_sender.send(handle_file(&file_handle, |data| { match serde_json::from_reader(data) { Ok(history) => Ok(Ok(history)), Err(err) if err.is_io() => Err(err.into()), Err(err) => Ok(Err(err)), } - }) - .await; + }).await); ctx.request_repaint(); } });