我按照快速入门指南进行操作。现在我试图返回一些超级简单的 JSON,但文档是错误的,并且无法在不进入 IRC 的情况下提交票证。
error[E0432]: unresolved import `rocket::serde::json`
--> src/main.rs:2:20
|
2 | use rocket::serde::json::Json;
| ^^^^ could not find `json` in `serde`
For more information about this error, try `rustc --explain E0432`.
error: could not compile `my-api` due to previous error
Run Code Online (Sandbox Code Playgroud)
Cargo.toml
[package]
name = "my-api"
version = "0.1.0"
edition = "2021"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rocket = "0.5.0-rc.1"
serde = "1.0.130"
Run Code Online (Sandbox Code Playgroud)
main.rs
[package]
name = "my-api"
version = "0.1.0"
edition = "2021"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rocket = "0.5.0-rc.1"
serde = "1.0.130"
Run Code Online (Sandbox Code Playgroud)
如果您转到此处,您会发现这几乎是文档的直接复制/粘贴。我对 Rust 的了解不够,无法解决依赖错误。
Cha*_*ffy 16
需要在您json的.rocketCargo.toml
[package]
name = "my-api"
version = "0.1.0"
edition = "2018" // cut back for testing with nixpkgs-provided rust
publish = false
[dependencies]
serde = "1.0.130"
[dependencies.rocket]
version = "0.5.0-rc.1"
features = ["json"]
Run Code Online (Sandbox Code Playgroud)
这记录在Rocket 源代码的注释中,该源代码在此处生成该文档。