-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
the trait rocket::request::FromFormValue<'_>
is not implemented for models::chrono::NaiveDate
#602
Comments
It looks like you're missing a few lines above the actual output you've pasted here. Rocket doesn't know how to create Login structs from the post request data, to your controller's arguments:
I think you just have to implement FromFormValue for the NaiveDate type yourself, like in the Field validation guide.
See FromFormValue trait for more information about this. |
But surely that leads to an orphaned impl, because he does not own NaiveDate or FromFormValue I think that you could however create a wrapper, and use that in your Login; i.e: struct NaiveDateForm(NaiveDate);
impl<'v> FromFormValue<'v> for NaiveDateForm {
type Error = &'v RawStr;
fn from_form_value(form_value: &'v RawStr) -> Result<NaiveDateForm, &'v RawStr> {
// here, parse NaiveDate and return an instance of the wrapper
}
}
impl Deref<NaiveDate> for NaiveDateForm{
fn deref(self)->NaiveDate{
self.0
}
} |
We don't have built-in support for In general, this is an issue caused by coherence, as @DJMcNab alludes to. The workaround is exactly as @DJMcNab writes, though the I think this answers the question. As such, I'm closing the issue out. Feel free to comment if you feel your question hasn't been answered. |
Now that there's no longer a |
I'm a bit suprised - Its super common in the rust ecosystem to gate an impl behind a feature. |
Any updates on this on Rocket v5? |
Setup
Versions
Rust:
rustc 1.25.0-nightly
Rocket:
0.3.8 (Apr 07, 2018)
Diesel:
version = "1.1.0"
Database:
PGsql 10.3
Operating System
Windows 10 Fall creators update
Feature Flags
chrono = { version = "0.4", features = ["serde"] }
diesel = { version = "1.1.0", features = ["postgres", "chrono", "large-tables" ] }
Problem Description
I got a "NaiveDate" field at a diesel insertable struct that derives from rocket's request::FromForm and the trait bound
models::chrono::NaiveDate: rocket::request::FromFormValue<'_>
is not being satisfied.#[derive(Insertable, Debug, FromForm)]
#[table_name="login"]
pub struct NewLogin {
pub username: String,
pub userpass: String,
pub creation_date: Option<self::chrono::NaiveDate>,
}
What is the expected output?
Successful compiling xD
What is the actual output?
error[E0277]: the trait bound
models::chrono::NaiveDate: rocket::request::FromFormValue<'>is not satisfied --> examples\freedu\src\models.rs:116:29 | 116 | #[derive(Insertable, Debug, FromForm)] | ^^^^^^^^ the trait
rocket::request::FromFormValue<'>is not implemented for
models::chrono::NaiveDate| = note: required because of the requirements on the impl of
rocket::request::FromFormValue<'_>for
std::option::Optionmodels::chrono::NaiveDate``Steps to reproduce
Full code source:
https://github.com/luis-vmjr/freedu/blob/master/src/models.rs
Checklist
The text was updated successfully, but these errors were encountered: