From 98e706af4a746caaf55e7bacfcac04c11028a8db Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sun, 21 Jan 2024 18:58:45 +0000 Subject: [PATCH] Store file io error in app state --- src/main.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index ae2a3c8..a47120f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,7 @@ enum Message { struct BookManagerApp { book_content: text_editor::Content, + io_error: Option, } impl Application for BookManagerApp { @@ -26,6 +27,7 @@ impl Application for BookManagerApp { ( Self { book_content: text_editor::Content::new(), + io_error: None, }, Command::perform( load_file(format!("{}/src/main.rs", env!("CARGO_MANIFEST_DIR"))), @@ -41,11 +43,10 @@ impl Application for BookManagerApp { fn update(&mut self, message: Self::Message) -> Command { match message { Message::Edit(action) => self.book_content.perform(action), - Message::FileOpened(result) => { - if let Ok(content) = result { - self.book_content = text_editor::Content::with_text(&content); - } - } + Message::FileOpened(result) => match result { + Ok(content) => self.book_content = text_editor::Content::with_text(&content), + Err(error) => self.io_error = Some(error), + }, } Command::none()