Hello! I'm trying to save form data x-www-form-urlencoded into csv file in my first Rust program, how can I deserialize actix_web form data and serialize it into csv file? Is it possible to use one struct for it? How to cover csv error scenario?
error[E0277]: the trait bound `actix_web::types::form::Form<FormData>: _IMPL_DESERIALIZE_FOR_FormData::_serde::Serialize` is not satisfied
--> src/main.rs:46:19
|
46 | wtr.serialize(form)?;
| ^^^^ the trait `_IMPL_DESERIALIZE_FOR_FormData::_serde::Serialize` is not implemented for `actix_web::types::form::Form<FormData>`
error[E0277]: the trait bound `csv::Error: actix_http::error::ResponseError` is not satisfied
--> src/main.rs:46:24
|
46 | wtr.serialize(form)?;
| ^ the trait `actix_http::error::ResponseError` is not implemented for `csv::Error`
|
= note: required because of the requirements on the impl of `std::convert::From<csv::Error>` for `actix_http::error::Error`
= note: required by `std::convert::From::from`
error: aborting due to 2 previous errors
I think this part is fine, I was able to get ie. form.fullname deserialized properly, difficult part is that I can't use this deserialized FormData to store them in wtr.serialize(form)?;, actually I don't know how it should be in the "proper way" in Rust
Thank you! You have solved one issue with struct.
Now I've got ^ the trait actix_http::error::ResponseError is not implemented for csv::Error
I removed Elvis operator and got new error:
| ---- move occurs because `form` has type `actix_web::types::form::Form<FormData>`, which does not implement the `Copy` trait
45 | let mut wtr = csv::Writer::from_writer(io::stdout());
46 | wtr.serialize(form.into_inner());
| ---- value moved here
...
51 | form.fullname
| ^^^^ value borrowed here after move
but maybe should I keep Elvis operator and handle error explicitly?
async fn contact(form: web::Form<FormData>) -> Result<String> {
let mut wtr = csv::Writer::from_writer(io::stdout());
let form = form.into_inner();
wtr.serialize(&form);
wtr.flush()?;
Ok(format!("Hello {}!", form.fullname))
}
but got
warning: unused `std::result::Result` that must be used
--> src/main.rs:47:5
|
47 | wtr.serialize(&form);
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_must_use)]` on by default
= note: this `Result` may be an `Err` variant, which should be handled
I tried also to use it directly
46 | let form = form.into_inner();
| ---- move occurs because `form` has type `FormData`, which does not implement the `Copy` trait
47 | wtr.serialize(form);
| ---- value moved here
...
50 | Ok(format!("Hello {}!", form.fullname))
| ^^^^^^^^^^^^^ value borrowed here after move