rust - How do I use rocket_contrib::Uuid in a form?
问题描述
I am using the 0.5.0-dev version of rocket and rocket_contrib. I want to use a Uuid
in my form, but I get the following compilation error:
the trait `FromFormField<'_>` is not implemented for `rocket_contrib::uuid::Uuid`
I do not understand this as according to the docs Uuid
implements FromFormField
. What am I doing wrong?
#[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 = "stackoverflow"
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"]
推荐阅读
- django - 为什么它显示的空路径不匹配任何这些
- git - 在 git diff 中,区分删除和移动
- python-3.x - DataFrame.write.parquet() 只使用一个执行器,不扩展
- python - LSTM 文本生成 Input_shape
- python - 如何从用户输入中对文本文件执行搜索
- database - 手动更新 ID 列会损害数据库吗?
- python - 洛书魔方总是返回假
- matlab - MATLAB - 频谱图函数
- c# - IDisposable 和私有 bool 已处理。这个怎么运作?
- wordpress - WordPress/ACF:自定义块类型仅在帖子数组中呈现一次