我遵循了快速入门指南。现在我正在尝试返回一些超级简单的 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
文件
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"
main.rs
#[macro_use] extern crate rocket;
use rocket::serde::{Serialize, json::Json};
#[derive(Serialize)]
struct Location {
lat: String,
lng: String,
}
#[get("/?<lat>&<lng>")]
fn location(lat: &str, lng: &str) -> Json<Location> {
Json(Location {
lat: 111.1111.to_string(),
lng: 222.2222.to_string(),
})
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![location])
}
如果你去这里,你会看到这几乎是文档的直接复制/粘贴。我对 Rust 的了解不够,无法解决依赖错误。