RC
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) }