A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 79184e819c17f4c9009d1f277b856469cb38d4d3 (897 bytes)[doc][blame][raw]
1
use serde::Serialize;3
#[derive(Debug, Serialize)]4
pub struct Response<T, E> {5
pub ok: bool,6
pub data: Option<T>,7
pub error: Option<E>,8
}10
impl Response<(), ()> {11
pub fn success() -> Result<tide::Body, tide::Error> {12
tide::Body::from_json(&Self { ok: true, data: None, error: None })13
}14
}16
impl<T> Response<T, ()> where T: Serialize {17
pub fn with(data: T) -> Result<tide::Body, tide::Error> {18
tide::Body::from_json(&Self { ok: true, data: Some(data), error: None })19
}20
pub fn with_option(data: Option<T>) -> Result<tide::Body, tide::Error> {21
tide::Body::from_json(&Self { ok: true, data, error: None })22
}23
}26
impl<E> Response<(), E> where E: Serialize {27
pub fn throw(error: E) -> Result<tide::Body, tide::Error> {28
tide::Body::from_json(&Self { ok: false, data: None, error: Some(error) })29
}30
}