diff --git a/src/io.rs b/src/io.rs index b97fc03..c36cf8d 100644 --- a/src/io.rs +++ b/src/io.rs @@ -1,7 +1,4 @@ -use std::{ - fs::{read_to_string, write}, - path::PathBuf, -}; +use std::path::PathBuf; use rfd::AsyncFileDialog; use tokio::fs; @@ -46,50 +43,3 @@ pub async fn save_file(path: Option, text: String) -> Result Err(err), } } - -pub fn save_file_to_disk(path: PathBuf, text: String) { - let save_result = write(path, text); - - match save_result { - Ok(_) => {} - Err(err) => eprintln!("Error: {}", err), - } -} - -pub fn load_file_from_disk(path: PathBuf) -> String { - let read_result = read_to_string(path); - read_result.unwrap_or_default() -} - -#[cfg(test)] -mod tests { - use super::*; - use std::fs::{self, remove_file}; - - #[test] - fn test_save_file_to_disk() { - let test_path = PathBuf::from("test_file.txt"); - let test_content = String::from("Hello, Chat!"); - - save_file_to_disk(test_path.clone(), test_content.clone()); - - let saved_content = fs::read_to_string(&test_path).unwrap(); - - assert_eq!(saved_content, test_content); - - let _ = remove_file(test_path); - } - - #[test] - fn test_load_file_from_disk() { - let test_path = PathBuf::from("test_file.txt"); - let test_content = String::from("Hello, Chat!"); - let _ = fs::write(test_path.clone(), test_content.clone()); - - let saved_content = load_file_from_disk(test_path.clone()); - - assert_eq!(saved_content, test_content); - - let _ = remove_file(test_path); - } -} diff --git a/src/main.rs b/src/main.rs index ed0867e..8e0b29b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,10 @@ pub fn main() -> iced::Result { .run() } +fn boot() -> State { + state::State::new() +} + fn update(state: &mut State, message: Message) -> Task { match message { Message::Edit(action) => handler::edit(state, action), @@ -59,10 +63,6 @@ fn view(state: &State) -> Element<'_, Message> { .into() } -fn boot() -> State { - state::State::new() -} - fn subscription(_state: &State) -> Subscription { event::listen_with(|e, _status, _win| -> Option { match e {