Interacting with the environment
In order to interact with the environment, we have to manage two things. First, we need to load, save, and edit the state of to-do items. Second, we also have to accept user input to edit and display data. Our program can achieve this by running the following steps for each process:
- Collect arguments from the user.
- Define a command (
get
,edit
,delete
, andcreate
) and define a to-do title from commandments. - Load a JSON file that stores the to-do items from previous runs of the program.
- Run a
get
,edit
,delete
, orcreate
function based on the command passed into the program, saving the result of the state in a JSON file at the end.
We can start making this four-step process possible by initially loading our state with the serde
crate.
Reading and writing JSON files
To install the serde
crate, we define the dependency in the Cargo.toml
file under the [dependencies]
section:
[dependencies] serde_json = {version = "...