Serving our to-do items
We are now at the stage of serving all our items to the browser. However, before we touch any of the server code, we need to add another struct from our core
module. We need a container that houses two lists of items for the pending and done items which takes the following form:
// File: to_do/core/src/structs.rs
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AllToDOItems {
pub pending: Vec<ToDoItem>,
pub done: Vec<ToDoItem>
}
You might recall that we load the data from the JSON file in hashmap form, meaning that we are going to need a from_hashmap
function for our AllToDoItems
struct with the code below:
// File: to_do/core/src/structs.rs
impl AllToDOItems {
pub fn from_hashmap(all_items: HashMap<String, ToDoItem>)
-> AllToDOItems {
let mut pending = Vec::new();
let mut done = Vec::new();
for (_, item) in all_items {
match item.status {
TaskStatus::PENDING...