Skip to main content

xtask_todo_lib/
error.rs

1//! Errors from todo operations.
2
3use std::fmt;
4
5use crate::id::TodoId;
6
7/// Errors from todo operations.
8#[derive(Debug)]
9pub enum TodoError {
10    /// Title was empty or invalid.
11    InvalidInput,
12    /// No todo with the given id.
13    NotFound(TodoId),
14}
15
16impl fmt::Display for TodoError {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            Self::InvalidInput => f.write_str("invalid input: title must be non-empty"),
20            Self::NotFound(id) => write!(f, "todo not found: {id}"),
21        }
22    }
23}
24
25impl std::error::Error for TodoError {}