我正在尝试使用 Rust 创建打印服务器,并在尝试发送 JSON 作为响应时遇到问题。
我在 Rocket 文档中发现发送 JSON 作为响应非常容易:您只需使用 Serde 库即可。
不幸的是,这对我来说并不是那么简单......
这是我当前的代码:
#[derive(Serialize,Deserialize)]
pub struct Printers {
pub printers: Vec<Printer>,
}
#[derive(Serialize,Deserialize)]
pub struct Printer {
pub device_type: String,
pub uid: String,
pub provider: String,
pub name: String,
pub connection: String,
pub version: u8,
pub manufacturer: String,
}
/**
* Here is my main problem
* -> I want to send back the Printers Object as a JSON
*/
#[get("/printers")]
fn printers(key: ApiKey<'_>) -> Json<Printers> {
let resp …Run Code Online (Sandbox Code Playgroud)