Day 1 - Building a Simple Command Line Todo List in Rust
Create a simple Rust command-line app to manage todos, learning basic file I/O and user interaction.
Introduction
Welcome to the first day of our 7-day Rust project series! Today, we'll create a basic command-line todo list application. This project will familiarize you with Rust's basic syntax, file I/O, and command-line argument handling.
Step 1: Setting Up Your Project
-
Create a new Rust project:
-
Folder Structure: Your folder should now look like this:
todo_list/ ├── Cargo.toml └── src/ └── main.rs
Step 2: Writing the Main Function
Open src/main.rs
and start with the basics:
Step 3: Implementing Helper Functions
Step 4: Running Your Project
To run your project:
Explanation:
-
Cargo.toml: This file contains metadata for your project and dependencies (although for this project, we don't need any external crates).
-
std::fs and std::io: These modules are used for file operations (reading and writing todos) and handling input/output operations.
-
main(): The entry point of our application. It manages the loop for user interaction.
-
CRUD Operations: Our functions
add_todo
,list_todos
,remove_todo
handle creating, reading, and deleting todos respectively. Thesave_todos
andload_todos
functions persist the todos to a file. -
Error Handling: Basic error handling is implemented with
.expect()
for simplicity, but in a real-world app, you'd want more robust error handling.
This project introduces basic Rust concepts like ownership, borrowing, error handling with Result
, file I/O, and basic CLI interactions. Enjoy building your first Rust project, and see you tomorrow for something a bit more graphical!
This blog post should give a comprehensive guide for beginners to follow along and understand the basics of Rust programming through a practical example.