如何在表单中使用 rocket_contrib::Uuid?
How do I use rocket_contrib::Uuid in a form?
我正在使用 0.5.0-dev 版本的 rocket 和 rocket_contrib。我想在我的表单中使用 Uuid
,但出现以下编译错误:
the trait `FromFormField<'_>` is not implemented for `rocket_contrib::uuid::Uuid`
我不明白这是根据 docs Uuid
实现的 FromFormField
。我做错了什么?
#[macro_use]
extern crate rocket;
use rocket::data::TempFile;
use rocket::form::{DataField, Form};
use rocket_contrib::uuid::Uuid;
#[derive(FromForm)]
struct FileUploadForm<'v> {
id: Uuid,
file: TempFile<'v>,
}
#[post("/upload", data = "<data>")]
fn upload(data: Form<FileUploadForm>) -> Result<String, std::io::Error> {
let id = "uuid".to_string();
Ok(id)
}
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", routes![upload])
}
#[rocket::main]
async fn main() {
rocket().launch().await;
}
我的Cargo.toml
不正确,我没有正确包含rocket_contrib
。正确的版本如下
[package]
name = "Whosebug"
version = "0.1.0"
edition = "2018"
[dependencies]
rocket = { git = "https://github.com/SergioBenitez/Rocket", version = "0.5.0-dev" }
[dependencies.rocket_contrib]
git = "https://github.com/SergioBenitez/Rocket"
version = "0.5.0-dev"
default-features = false
features = ["uuid"]
我正在使用 0.5.0-dev 版本的 rocket 和 rocket_contrib。我想在我的表单中使用 Uuid
,但出现以下编译错误:
the trait `FromFormField<'_>` is not implemented for `rocket_contrib::uuid::Uuid`
我不明白这是根据 docs Uuid
实现的 FromFormField
。我做错了什么?
#[macro_use]
extern crate rocket;
use rocket::data::TempFile;
use rocket::form::{DataField, Form};
use rocket_contrib::uuid::Uuid;
#[derive(FromForm)]
struct FileUploadForm<'v> {
id: Uuid,
file: TempFile<'v>,
}
#[post("/upload", data = "<data>")]
fn upload(data: Form<FileUploadForm>) -> Result<String, std::io::Error> {
let id = "uuid".to_string();
Ok(id)
}
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", routes![upload])
}
#[rocket::main]
async fn main() {
rocket().launch().await;
}
我的Cargo.toml
不正确,我没有正确包含rocket_contrib
。正确的版本如下
[package]
name = "Whosebug"
version = "0.1.0"
edition = "2018"
[dependencies]
rocket = { git = "https://github.com/SergioBenitez/Rocket", version = "0.5.0-dev" }
[dependencies.rocket_contrib]
git = "https://github.com/SergioBenitez/Rocket"
version = "0.5.0-dev"
default-features = false
features = ["uuid"]