use rocket::serde::json::Json; use serde::{Deserialize, Serialize}; /// Represents a JSON response that can be either an error or a success /// Is used as a helper to return JSON responses from the backend #[derive(Debug, Serialize, Deserialize)] pub enum JsonResult { Ok(A), Error(JsonError), } #[derive(Debug, Serialize, Deserialize)] pub struct JsonError { reason: String, } impl JsonResult { pub fn ok(data: A) -> Json> { Json(JsonResult::Ok(data)) } pub fn err(reason: String) -> Json> { Json(JsonResult::Error(JsonError { reason })) } }