Created
March 31, 2019 19:18
-
-
Save bjornharrtell/5ea10f0003378bf76d8f2abe04079e2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(proc_macro_hygiene, decl_macro)] | |
#[macro_use] extern crate rocket; | |
#[macro_use] extern crate serde_derive; | |
extern crate rocket_contrib; | |
use rocket_contrib::json::{Json}; | |
#[derive(Serialize)] | |
pub struct User { | |
name: Option<String> | |
} | |
#[derive(Serialize)] | |
pub struct JsonError { | |
message: String | |
} | |
#[get("/")] | |
fn get() -> Result<Json<User>, Json<JsonError>> { | |
Err(Json(JsonError { message: "Unknown".to_string() })) | |
} | |
fn main() { | |
rocket::ignite() | |
.mount("/", routes![get]) | |
.launch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem is that the Err type needs to implement Debug, #[derive(Serialize)] -> #[derive(Serialize, Debug)] fixes the problem.