Skip to main content

TodoList

Struct TodoList 

Source
pub struct TodoList<S> { /* private fields */ }
Expand description

Facade for todo operations. Holds a store (default: in-memory).

Implementations§

Source§

impl TodoList<InMemoryStore>

Source

pub fn new() -> Self

Creates a new list with in-memory storage.

Source§

impl<S: Store> TodoList<S>

Source

pub const fn with_store(store: S) -> Self

Builds a list with the given store (e.g. for testing or custom backends).

Source

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.

Source

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.

Source

pub fn get(&self, id: TodoId) -> Option<Todo>

Returns the todo with the given id, if it exists.

Source

pub fn list(&self) -> Vec<Todo>

Returns all todos in creation order.

Source

pub fn list_with_options(&self, options: &ListOptions) -> Vec<Todo>

Returns todos filtered and sorted according to options.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn search(&self, keyword: &str) -> Vec<Todo>

Search todos by keyword (matches title; optionally description and tags when present).

Source

pub fn stats(&self) -> (usize, usize, usize)

Returns counts: total, incomplete, complete.

Trait Implementations§

Source§

impl Default for TodoList<InMemoryStore>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S> Freeze for TodoList<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for TodoList<S>
where S: RefUnwindSafe,

§

impl<S> Send for TodoList<S>
where S: Send,

§

impl<S> Sync for TodoList<S>
where S: Sync,

§

impl<S> Unpin for TodoList<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for TodoList<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for TodoList<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.