Skip to content

运行效果

bash
# 添加待办事项
todo add "学习 Rust 基础"
todo add "完成所有权章节"
todo add "编写第一个项目"

# 列出待办事项
todo list

# 标记完成
todo done 1

# 列出所有(包括已完成)
todo list --all

# 删除待办事项
todo remove 2

# 清空已完成
todo clear

输出示例

✓ 添加成功 待办事项 #1: 学习 Rust 基础

待办事项列表
──────────────────────────────────────────────────
○ [#1] 学习 Rust 基础 - 2024-01-15 10:30:00
○ [#2] 完成所有权章节 - 2024-01-15 10:31:00
○ [#3] 编写第一个项目 - 2024-01-15 10:32:00
──────────────────────────────────────────────────
总计: 3 项, 已完成: 0 项

✓ 待办事项 #1 已完成

待办事项列表
──────────────────────────────────────────────────
✓ [#1] 学习 Rust 基础 - 2024-01-15 10:30:00
○ [#2] 完成所有权章节 - 2024-01-15 10:31:00
○ [#3] 编写第一个项目 - 2024-01-15 10:32:00
──────────────────────────────────────────────────
总计: 3 项, 已完成: 1 项

扩展功能

添加优先级

rust
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Todo {
    pub id: u32,
    pub content: String,
    pub done: bool,
    pub created_at: String,
    pub priority: Priority,  // 新增
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Priority {
    Low,
    Medium,
    High,
}
▶ Run

添加标签

rust
pub struct Todo {
    pub id: u32,
    pub content: String,
    pub done: bool,
    pub created_at: String,
    pub tags: Vec<String>,  // 新增
}
▶ Run

添加截止日期

rust
pub struct Todo {
    pub id: u32,
    pub content: String,
    pub done: bool,
    pub created_at: String,
    pub due_date: Option<String>,  // 新增
}
▶ Run

小结

本项目涵盖:

  • ✅ Clap 命令行参数解析
  • ✅ Serde 数据序列化
  • ✅ 文件读写操作
  • ✅ 模块化代码组织
  • ✅ 错误处理最佳实践
  • ✅ 彩色终端输出