pub struct TodoState {
pub items: Vec<TodoItem>,
/* private fields */
}Expand description
Shared TODO state that can be persisted.
Fields§
§items: Vec<TodoItem>The list of TODO items.
Implementations§
Source§impl TodoState
impl TodoState
Sourcepub const fn with_storage(path: PathBuf) -> Self
pub const fn with_storage(path: PathBuf) -> Self
Creates a new TODO state with persistence.
Sourcepub fn set_storage_path(&mut self, path: PathBuf)
pub fn set_storage_path(&mut self, path: PathBuf)
Sets the storage path for persistence.
Sourcepub async fn load(&mut self) -> Result<()>
pub async fn load(&mut self) -> Result<()>
Loads todos from storage if path is set.
§Errors
Returns an error if the file cannot be read or parsed.
Sourcepub async fn save(&self) -> Result<()>
pub async fn save(&self) -> Result<()>
Saves todos to storage if path is set.
The write is atomic: the JSON is written to a uniquely-named temp file
in the same directory and then renamed over the target (atomic on
POSIX). A crash or a cancelled future mid-write can therefore never
leave a truncated/invalid file in place, which load
would otherwise fail to parse permanently.
§Errors
Returns an error if the file cannot be written or renamed into place.
Sourcepub fn count_by_status(&self) -> (usize, usize, usize)
pub fn count_by_status(&self) -> (usize, usize, usize)
Returns the count of items by status.
Sourcepub fn current_task(&self) -> Option<&TodoItem>
pub fn current_task(&self) -> Option<&TodoItem>
Returns the currently in-progress item, if any.
Sourcepub fn format_display(&self) -> String
pub fn format_display(&self) -> String
Formats the TODO list for display.