The objective is to create an api to parse a list of _todos_ that is organized in a JSON file,
handling all possible errors in a multiple error system.
The objective is to create an API to parse a list of _todos_ that are organized in a JSON file. You must handle all possible errors in a multiple error system.
Organization of the JSON file:
@ -19,38 +18,29 @@ Organization of the JSON file:
#### err.rs
Create a module in another file called **err.rs** which handles the boxing of errors.
This module must implement an `enum` called `ParseErr` which will take care of the
parsing errors. It must have the following elements:
Create a module in a file named **err.rs** which handles the boxing of errors.
- Empty
- Malformed, which has a dynamic boxed error as element
This module must implement an `enum` called `ParseErr` which will take care of the parsing errors. It must have the following elements:
A structure called `ReadErr` which will take care of the reading errors, having just an element called `child_err` of type `Box<dyn Error>`.
- `Empty`
- `Malformed`: which has a dynamic boxed error as element
For each data structure you will have to implement a function called `fmt` for the trait `Display` which writes
out the message **"Fail to parse todo"** in case it is a parsing error. Otherwise, it should write the message
**"Fail to read todo file"**.
For the `Error` trait the following functions (methods) have to be implemented:
A structure called `ReadErr` which will take care of the reading errors, with an element called `child_err` of type `Box<dyn Error>`.
For each data structure, you will have to implement a function called `fmt` for the `Display` trait. It should write the message **"Fail to parse todo"** in the case of any parsing error. Otherwise, it should write the message **"Fail to read todo file"**.
For the `Error` trait, the following functions (methods) have to be implemented:
- `source` which returns an `Option` with the error:
- For the `ReadErr` it must just return the option with the error
- For the `ParseErr` it will return an option which can be `None` if the tasks are **empty** otherwise the error, if
the parsing is **malformed**.
- For the `ReadErr`, it must return the option with the error.
- For the `ParseErr`, it will return an option which is `None` if the tasks are **empty**, and the error if the parsing is **malformed**.
#### lib.rs
In the **lib** file you will have to implement a **function** called `get_todo` which receives a string and returns a Result
which can be the structure `TodoList` or a boxing error. This **function** must be able to deserialize the json file.
Basically it must parse and read the JSON file and return the `TodoList` if everything is fine, otherwise it returns the error.
### Notions
In the **lib** file you will have to implement a **function** called `get_todo` which receives a string and returns a `Result` which can be the structure `TodoList` or a boxing error. This **function** must be able to deserialize the json file.