pub struct TodoList<S> { /* private fields */ }Expand description
Facade for todo operations. Holds a store (default: in-memory).
Implementations§
Source§impl TodoList<InMemoryStore>
impl TodoList<InMemoryStore>
Source§impl<S: Store> TodoList<S>
impl<S: Store> TodoList<S>
Sourcepub const fn with_store(store: S) -> Self
pub const fn with_store(store: S) -> Self
Builds a list with the given store (e.g. for testing or custom backends).
Sourcepub fn create(&mut self, title: impl AsRef<str>) -> Result<TodoId, TodoError>
pub fn create(&mut self, title: impl AsRef<str>) -> Result<TodoId, TodoError>
Creates a todo with the given title. Returns its TodoId or an error if title is invalid.
§Errors
Returns TodoError::InvalidInput if the title is empty or only whitespace after trim.
Sourcepub fn add_todo(&mut self, todo: &Todo) -> TodoId
pub fn add_todo(&mut self, todo: &Todo) -> TodoId
Inserts an existing todo’s content with a new id (e.g. for import/merge). Returns the new TodoId.
Sourcepub fn get(&self, id: TodoId) -> Option<Todo>
pub fn get(&self, id: TodoId) -> Option<Todo>
Returns the todo with the given id, if it exists.
Sourcepub fn list_with_options(&self, options: &ListOptions) -> Vec<Todo>
pub fn list_with_options(&self, options: &ListOptions) -> Vec<Todo>
Returns todos filtered and sorted according to options.
Sourcepub fn update_title(
&mut self,
id: TodoId,
title: impl AsRef<str>,
) -> Result<(), TodoError>
pub fn update_title( &mut self, id: TodoId, title: impl AsRef<str>, ) -> Result<(), TodoError>
Updates the title of the todo with the given id.
§Errors
Returns TodoError::NotFound(id) if no todo with that id exists.
Returns TodoError::InvalidInput if the new title is empty or only whitespace.
Sourcepub fn update(&mut self, id: TodoId, patch: TodoPatch) -> Result<(), TodoError>
pub fn update(&mut self, id: TodoId, patch: TodoPatch) -> Result<(), TodoError>
Applies a partial update to the todo with the given id. Only fields set in patch are updated.
§Errors
Returns TodoError::NotFound(id) if no todo with that id exists.
Returns TodoError::InvalidInput if patch.title is Some and empty/whitespace.
Sourcepub fn complete(&mut self, id: TodoId, no_next: bool) -> Result<(), TodoError>
pub fn complete(&mut self, id: TodoId, no_next: bool) -> Result<(), TodoError>
Marks the todo with the given TodoId as completed.
§Errors
Returns TodoError::NotFound(id) if no todo with that id exists.
Marks the todo as completed. If it has a repeat rule and no_next is false, creates the next instance.
Sourcepub fn delete(&mut self, id: TodoId) -> Result<(), TodoError>
pub fn delete(&mut self, id: TodoId) -> Result<(), TodoError>
Removes the todo with the given TodoId.
§Errors
Returns TodoError::NotFound(id) if no todo with that id exists.