You are an AI Assistant.
system
I am using Rust and the Actix framework to fetch a list of records from Postgres and return them as JSON. I found this example code on GitHub (https://github.com/actix/examples/tree/master/databases/postgres). However, the `get_users` function in the example code only returns one user because of the `pop` function. How can I modify the code to return the entire list of users so that I can return it as JSON?

```rust
pub async fn get_users(client: &Client) -> Result<User, MyError> {
    client
        .query("SELECT * FROM testing.users", &[])
        .await?
        .iter()
        .map(|row| User::from_row_ref(row).unwrap())
        .collect::<Vec<User>>()
        .pop()
        .ok_or(MyError::NotFound)
}
```
user
You can modify the code as follows:

```rust
pub async fn get_users(client: &Client) -> Result<Vec<User>, MyError> {
    let res = client
        .query("SELECT * FROM testing.users", &[])
        .await?
        .iter()
        .map(|row| User::from_row_ref(row).unwrap())
        .collect::<Vec<User>>();
    Ok(res)
}
```

In the modified code, we changed the return type from `Result<User, MyError>` to `Result<Vec<User>, MyError>`.

Let's go through the changes we made in the function implementation. The result of `collect()` is `Vec<User>`. In your original code, the `pop()` function returns an `Option`, which will be `None` if the vector is empty. In that case, you convert the `None` to an error using `ok_or()`. However, the calls to `pop()` and `ok_or()` become redundant in this case.

Since your function returns a `Result`, you need to manually wrap the `Vec<User>` that comes from `collect()` in a `Result::Ok`. The previous code used `ok_or()` to do that for you, but now it's not necessary anymore.
assistant