egui: get rid of overabstraction file_handler::push_file_to_read

This commit is contained in:
Alain Emilia Anna Zscheile 2024-10-03 13:49:33 +02:00
parent 25a692aab9
commit 4fef94a5c5
2 changed files with 6 additions and 20 deletions

View File

@ -46,19 +46,7 @@ impl io::BufRead for FileHandlerData {
fhd_forward!(fn consume(&mut self, amt: usize)); fhd_forward!(fn consume(&mut self, amt: usize));
} }
#[inline] pub async fn handle_file<R, E, C>(file_handle: &rfd::FileHandle, callback: C) -> Result<R, E>
pub async fn push_file_to_read<R, E, C>(
file_handle: &rfd::FileHandle,
sender: Sender<Result<R, E>>,
callback: C,
) where
E: From<std::io::Error>,
C: FnOnce(FileHandlerData) -> Result<R, E>,
{
let _ = sender.send(handle_text(&file_handle, callback).await);
}
async fn handle_text<R, E, C>(file_handle: &rfd::FileHandle, callback: C) -> Result<R, E>
where where
E: From<std::io::Error>, E: From<std::io::Error>,
C: FnOnce(FileHandlerData) -> Result<R, E>, C: FnOnce(FileHandlerData) -> Result<R, E>,

View File

@ -22,7 +22,7 @@ use crate::{
action::{Action, Switch, Trigger}, action::{Action, Switch, Trigger},
activity::{ActivityStatus, ActivityStepperWithStatus}, activity::{ActivityStatus, ActivityStepperWithStatus},
app::execute, app::execute,
file_handler::{push_file_to_read, FileHandlerData}, file_handler::{handle_file, FileHandlerData},
overlay::Overlay, overlay::Overlay,
translator::Translator, translator::Translator,
viewport::Viewport, viewport::Viewport,
@ -243,10 +243,9 @@ impl MenuBar {
execute(async move { execute(async move {
if let Some(file_handle) = task.await { 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) SpecctraDesign::load(data)
}) }).await);
.await;
ctx.request_repaint(); ctx.request_repaint();
} }
}); });
@ -285,14 +284,13 @@ impl MenuBar {
execute(async move { execute(async move {
if let Some(file_handle) = task.await { 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) { match serde_json::from_reader(data) {
Ok(history) => Ok(Ok(history)), Ok(history) => Ok(Ok(history)),
Err(err) if err.is_io() => Err(err.into()), Err(err) if err.is_io() => Err(err.into()),
Err(err) => Ok(Err(err)), Err(err) => Ok(Err(err)),
} }
}) }).await);
.await;
ctx.request_repaint(); ctx.request_repaint();
} }
}); });