this is the error I'm getting from the following code:
error[E0277]: the `?` operator can only be applied to values that implement `Try`
--> src/users/db.rs:24:15
|
24 | let res = client
| _______________^
25 | | .query(
26 | | &statement,
27 | | &[
... |
37 | | .map(|row| CreateUsers::from_row_ref(row).unwrap())
38 | | .unwrap()?;
| |__________________^ the `?` operator cannot be applied to type `models::CreateUsers`
What should I use instead of ?
pub async fn users_add(client: &Client, selfobj: CreateUsers) -> Result<CreateUsers, ServiceError> {
let statement = client
.prepare( "INSERT INTO public.users ( username, password, email) VALUES ($1, $2, $3) RETURNING id, username, password, email",
)
.await
.unwrap();
let res = client
.query(
&statement,
&[&selfobj.username, &selfobj.password, &selfobj.email, ],
)
.await
.expect("Error creating users")
.last()
.map(|row| CreateUsers::from_row_ref(row).unwrap())
.unwrap()?;
match res {
Ok(object) => object,
Err(e) => Err(ServiceError::DuplicateValue(e)), // Err(e) => HttpResponse::InternalServerError().json(e.to_string())
}
}