Failed attempt at rendering JSON for the rest view
I think something changed for rocket 0.5 becuase rustc is telling me: ``` the trait `Responder<'_, '_>` is not implemented for `rocket_contrib::json::Json<Person>` ``` Which I think doesn't make sense. It's their contrib wrapper over serde? It's versioned ~.4 though so I think I need to bump that.
This commit is contained in:
parent
591adcd000
commit
e73a55cfeb
File diff suppressed because it is too large
Load Diff
|
@ -9,3 +9,10 @@ edition = "2018"
|
|||
juniper_rocket = "0.8.0"
|
||||
juniper = "0.15.7"
|
||||
rocket = "0.5.0-rc.1"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
||||
[dependencies.rocket_contrib]
|
||||
version = "0.4.10"
|
||||
default-features = false
|
||||
features = ["json"]
|
|
@ -1,7 +1,8 @@
|
|||
use std::sync::{ atomic::AtomicUsize, atomic::Ordering, Mutex };
|
||||
use std::{ collections::HashMap };
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct Person {
|
||||
id: String,
|
||||
name: String,
|
||||
|
|
12
src/rest.rs
12
src/rest.rs
|
@ -1,12 +1,16 @@
|
|||
use rocket::fairing::AdHoc;
|
||||
use rocket::State;
|
||||
use crate::model::Database;
|
||||
use rocket_contrib::json::Json;
|
||||
use crate::model::{
|
||||
Database,
|
||||
Person,
|
||||
};
|
||||
|
||||
#[rocket::get("/rest/<id>")]
|
||||
fn get_rest(id: String, context: &State<Database>) -> Option<String> {
|
||||
#[rocket::get("/rest/<id>", format = "json")]
|
||||
fn get_rest(id: String, context: &State<Database>) -> Option<Json<Person>> {
|
||||
match context.get_person(&id) {
|
||||
None => None,
|
||||
Some(person) => Some(person.name().unwrap().to_string())
|
||||
Some(person) => Some(Json(person))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue