1

我正在尝试使用火箭处理程序返回 Json 数据。我看过许多其他具有相同问题的帖子,基本上每个没有实现 serde::Deserialize/serde::Serialize 的人的解决方案。有没有人有办法解决吗?

Rocket_contrib 文档

use rocket_contrib::json::Json;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct MyStruct;

pub fn get_timestamps(pool: &State<Pool>) -> Json<MyStruct> {
    ^^^^^^^^^^^^^^ the trait `Responder<'_, '_>` is not implemented for `rocket_contrib::json::Json<MyStruct>`

货运.toml

[dependencies]
rand = "0.8.4"
bytes = "1"
mysql = "*"
dotenv = "0.15.0"
serde = { version = "1", features = ["derive"] }
serde_derive = "1.0.127"
diesel = "1.4.7"
chrono = "0.4.19"
serde_json = "1.0"
rocket = "0.5.0-rc.1"

[dependencies.rocket_contrib]
version = "0.4"
default-features = false
features = ["json"]
4

0 回答 0