【发布时间】:2022-08-18 23:59:26
【问题描述】:
当我尝试为这样的 rust 结构添加 JsonSchema 时:
use std::time::Duration;
use chrono::{DateTime, Utc};
use tokio::time;
use rocket_okapi::okapi::schemars;
use rocket_okapi::okapi::schemars::JsonSchema;
#[tokio::main]
async fn main() {
}
#[derive( Serialize, Deserialize,Default, Clone, JsonSchema)]
pub struct ArticleResponse {
pub pub_time: Option<DateTime<Utc>>,
}
使用 cargo build 命令编译时显示错误:
error[E0277]: the trait bound `DateTime<Utc>: JsonSchema` is not satisfied
--> src/main.rs:12:50
|
12 | #[derive( Serialize, Deserialize,Default, Clone, JsonSchema)]
| ^^^^^^^^^^ the trait `JsonSchema` is not implemented for `DateTime<Utc>`
我应该怎么做才能为ArticleResponse 添加JsonSchema?这是 toml 的依赖项:
[package]
name = \"rust-learn\"
version = \"0.1.0\"
edition = \"2018\"
[dependencies]
rocket = { version = \"=0.5.0-rc.2\", features = [\"json\"] }
serde = { version = \"1.0.64\", features = [\"derive\"] }
serde_json = \"1.0.64\"
serde_derive = \"1.0\"
# database
diesel = { version = \"1.4.7\", features = [\"postgres\",\"serde_json\"] }
dotenv = \"0.15.0\"
chrono = { version = \"0.4\", features = [\"serde\"] }
diesel_full_text_search = { git = \"https://github.com/RedDwarfTech/diesel_full_text_search.git\"}
rust_wheel = { git = \"https://github.com/jiangxiaoqiang/rust_wheel.git\" }
tokio = { version = \"1.17.0\", features = [\"full\"] }
okapi = { git = \"https://github.com/GREsau/okapi.git\"}
schemars = \"0.7\"
rocket_okapi = { git = \"https://github.com/GREsau/okapi.git\", features = [\"swagger\", \"rapidoc\"] }