A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: cd18c5e5420979b4a90a60ad4506a78e64eca587 (847 bytes)[doc][blame][raw]
1
use crate::error::Error;2
use serde::Serialize;4
#[derive(Debug, Serialize)]5
pub struct Response<T, E> {6
pub ok: bool,7
pub data: Option<T>,8
pub error: Option<E>,9
}11
impl Response<(), ()> {12
pub fn respond(body: Result<tide::Body, tide::Error>) -> tide::Result {13
Ok(tide::Response::builder(200).body(body.unwrap()).build())14
}15
}17
impl<T> Response<T, ()>18
where19
T: Serialize,20
{21
pub fn with(data: T) -> tide::Result {22
Response::respond(tide::Body::from_json(&Self {23
ok: true,24
data: Some(data),25
error: None,26
}))27
}28
}30
impl Response<(), Error> {31
pub fn throw(message: &str) -> tide::Result {32
Response::respond(tide::Body::from_json(&Self {33
ok: false,34
data: None,35
error: Some(Error::new(message)),36
}))37
}38
}