Skip to content

AleksandrZin/to_do_app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ToDo App in Rust

Video Demo: Video

Description:

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.

Structure:

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.

How it works:

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.

Standard process:

Add:

  1. The application starts by parsing the command line arguments using the clap crate.
  2. It then creates a connection to the SQLite database using the rusqlite crate.
  3. It then creates a table in the database if it doesn't already exist.
  4. It creates an instance of the Task structure and populates it with the data from the command line arguments.
  5. It then adds the task to the database using the rusqlite crate.

Edit:

  1. The application starts by parsing the command line arguments using the clap crate.
  2. It converts input into vector of EditRequest enums by using vec_from_command method.
  3. Then the method edit_db is called on all members of the vector. Which edits the database.

Delete:

  1. The application starts by parsing the command line arguments using the clap crate.
  2. It deletes specified by ID task from the database

List:

  1. The application starts by parsing the command line arguments using the clap crate.
  2. Using "SELECT * FROM tasks" query, it gets all tasks from the database.
  3. Then Task's method pretty_print is called on all tasks.

Done:

  1. The application starts by parsing the command line arguments using the clap crate.
  2. It uses UPDATE query to mark task as done.

What I wanted to do but I didn't:

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.

What I would do differently:

  • Use JSON instead of SQLite...
  • I am not sure that Task struct 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.

What I learned:

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages