diff --git a/src/main.rs b/src/main.rs index e7e7755..3809671 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ use clap::{Parser, Subcommand}; use serde::{Deserialize, Serialize}; +use std::fs; +use std::path::Path; #[derive(Parser)] #[command(name = "todo")] @@ -30,6 +32,24 @@ struct TodoList { next_id: usize, } +impl TodoList { + fn new() -> Self { + TodoList { + tasks: Vec::new(), + next_id: 1, + } + } + + fn load_from_file(filename: &str) -> Result> { + if Path::new(filename).exists() { + let contents = fs::read_to_string(filename)?; + let todo_list = serde_json::from_str(&contents)?; + Ok(todo_list) + } else { + Ok(TodoList::new()) + } + } +} fn main() { let cli = Cli::parse(); match cli.command {