Hi there,
this might be a bug, but I guess I am overseeing something.
I am using Rocket 0.4 on Windows GNU right now. I just upgraded from Rocket 0.3.17 and now I am struggling a bit with some changes introduced in 0.4.
I cannot compile the following code because it says that it would miss the implementation of FromFormValue. However, my Form struct only contains f64:
//....
#[derive(FromForm)]
pub struct ErrorCalcForm {
pub mz: f64,
pub error: f64,
}
/// Dalton to ppm
#[get("/datoppm?<data>")]
pub fn errorcalc_datoppm(_user: UserId, data: Form<ErrorCalcForm>, context: State<SafeContext>) -> Template {
let mut context = context.lock().unwrap();
context.insert("mz_theo", &Some(format!("{:.4}", data.mz)));
context.insert("da", &Some(format!("{:.4}", data.error)));
context.insert(
"ppm",
&Some(format!("{:.2}", da_to_ppm(data.mz, data.error))),
);
Template::render("errorcalc", &context.clone())
}
//...
The error is:
error[E0277]: the trait bound `rocket::request::Form<errorcalc::ErrorCalcForm>: rocket::request::FromFormValue<'_>` is not satisfied
--> src\errorcalc.rs:53:41
|
53 | pub fn errorcalc_datoppm(_user: UserId, data: Form<ErrorCalcForm>, context: State<SafeContext>) -> Template {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `rocket::request::FromFormValue<'_>` is not implemented for `rocket::request::Form<errorcalc::ErrorCalcForm>`
According to the documentation, FromFormValue is implemented for f64. Why does it not work, then?
Thx for any help!
This is related to the query string handling changes (second in the list at https://github.com/SergioBenitez/Rocket/blob/master/CHANGELOG.md#breaking-changes).
The problem here is that ...?<data> now means "one value" (FromFormValue), but Form<T> is "multiple values" and doesn't implement that. You probably want ...?<data..> instead.
Forgot to mention: You could also use "?<mz>&<error>" with mz and error declared in the route instead of a separate form type.
This is the second bullet point of the CHANGELOG.