January 2019
Intermediate to advanced
520 pages
14h 32m
English
tasks_handler locks a Mutex with IndexMap to iterate over all Record values to render them as a part of the Tasks struct:
fn tasks_handler(req: HttpRequest<State>) -> impl Future<Item = HttpResponse, Error = WebError> { let tasks: Vec<_> = req .state() .tasks .lock() .unwrap() .values() .cloned() .collect(); let tmpl = Tasks { tasks }; future::ok(HttpResponse::Ok().body(tmpl.render().unwrap()))}
If you remember, we added the askama crate to render templates. Create a templates folder in the root of project and add a tasks.html file with some HTML code that contains at least the following rendering table:
<table> <thead> <tr> <th>Task ID</th> <th>Timestamp</th> <th>Status</th> </tr> </thead> <tbody> {% for task in tasks %} <tr> ...Read now
Unlock full access