Video Demo: Video
It is a simple CLI To Do application written in Rust and was written as a final project for CS50 course. All interactions are done via commands in the terminal. For help on how to use the application, type ./to_do_app help in the terminal or just ./to_do_app.
Application allows you to add, edit, remove, list, and mark tasks as complete. Tasks are stored in SQLite database and have a title, description, priority, and completion status.
The application is structured into three main modules:
- 'main.rs' - contains the main function of the application.
- 'cli.rs' - contains the command line interface functions and structures for the application.
- 'task.rs' - contains the Task and other related to it structures (EditRequest and Priority structures). In addition to that, the applications create a SQLite database file named 'todo.db' in the current directory. I decided to separate the project into these three modules mostly for readability and the way I did it looked the most logical to me.
This application uses clap crate (Rust's name for libraries) to parse command line arguments. It is really powerful and helpfull. All usage information is generated automatically with minimal effort from my side. It also helped to get the arguments in useable format.
The application uses rusqlite crate to interact with the SQLite database. And it was pain to use. There is not much documantation and examples on how to use it. But Cody AI helped with this. Retroactivly, I would prefer to use JSON files to store data.
- The application starts by parsing the command line arguments using the
clapcrate. - It then creates a connection to the SQLite database using the
rusqlitecrate. - It then creates a table in the database if it doesn't already exist.
- It creates an instance of the
Taskstructure and populates it with the data from the command line arguments. - It then adds the task to the database using the
rusqlitecrate.
- The application starts by parsing the command line arguments using the
clapcrate. - It converts input into vector of
EditRequestenums by usingvec_from_commandmethod. - Then the method
edit_dbis called on all members of the vector. Which edits the database.
- The application starts by parsing the command line arguments using the
clapcrate. - It deletes specified by ID task from the database
- The application starts by parsing the command line arguments using the
clapcrate. - Using "SELECT * FROM tasks" query, it gets all tasks from the database.
- Then
Task's methodpretty_printis called on all tasks.
- The application starts by parsing the command line arguments using the
clapcrate. - It uses
UPDATEquery to mark task as done.
Originally, I wanted Task to have due_date and tags fields. But when I started implementing them I realized that working with date and time can be chalanging and I wasn't sure how to implement tags.
In my notes that I wrote in the start, I wrote that I wanted to make a terminal UI and a way to filter tasks when calling list subcommand.
Of course now when I have this simpler app I can add these features, but I decided to stop here, since the perfection is unreachable and I feel like I learned enough from this project.
- Use JSON instead of SQLite...
- I am not sure that
Taskstruct is much useful. It is only used when adding a task to the database and when printing it. You can also see that there are few method for the struct that are commented out, since I realized that editing tasks is easier inside the database. I feel like I could do something different and more ellegent than this.
A LOT! I was not familiar with Rust at all before this project. I enjoyed C part of CS50 course, and I wanted to make something using low level language. I heard a lot about Rust and I wanted to try it. I am not sure if I will use it in the future, since I am trying to start a Data Analitics carier, but I am glad that I tried it. I've read a lot. (Rust's book)[https://doc.rust-lang.org/book/title-page.html] until chapter 11 and example of (CLI application) [https://rust-cli.github.io/book/index.html]. Without this knowlage I doubt that I would manage to make the app. Rust is realy interesting languge that has strcit design joices that helps to write more save and comprehensive code. I was expectinc something more si,ilar to C, but it wasn't. But if i will need to write something in low level languge I defenetly would choose Rust over C. I also used Cody AI to help me with some parts of the code.