Search posts, tags, users, and pages
TL;DR: Le code https://github.com/dirien/quick-bites/tree/main/rust-actix-web-rest-api Introduction This article walks through building a REST API in Rust using the Actix Web framework. The best way to learn something new? Try it yourself, make mis...
Engin Diri
@ediri · Germany
Customer Experience Architect @ Pulumi
Cloud Native Pilgrim | Kubernetes Enthusiast | Serverless Believer | Customer Experience Architect @ Pulumi | (he/him) | CK{A,AD} |
Markdown supported · ⌘↵ to post
Ruge Wit
Inside Database::update_todo_by_id we create a new todo, but don't fill the field "created_at", so that field will be null
Raphael Carubbi
you get by id first and then pass the current value to the new Todo instance:
pub fn update_todo_by_id(&self, id: &str, todo: Todo) -> Option<Todo> { let mut todos = self.todos.lock().unwrap(); let updated_at = Utc::now(); let index = todos.iter().position(|todo| todo.id == Some(id.to_string()))?; let todo = Todo { id: Some(id.to_string()), updated_at: Some(updated_at), created_at: todos[index].created_at, ..todo }; todos[index] = todo.clone(); Some(todo) }
Anna Smith
Just wanted to say this worked perfectly, thank you!
Ruge Wit
Inside Database::update_todo_by_id we create a new todo, but don't fill the field "created_at", so that field will be null