A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: f038310ef0fcafed9b58c24c8467accb897ed347 (1415 bytes)[doc][blame][raw]
1
use std::fmt::Display;2
use serde::Serialize;4
mod config;6
pub mod model;7
pub mod middleware;9
pub use config::Config;11
pub struct Utils {}13
impl Utils {14
pub fn null<T>(value: &Option<T>) -> String where T: Display {15
match value {16
Some(value) => format!("'{}'", &value),17
None => "NULL".to_string(),18
}19
}20
}22
#[derive(Debug, Clone)]23
pub struct State {24
pub config: Config,25
}27
impl State {28
pub fn new(config: Config) -> Self {29
Self { config }30
}31
}33
#[derive(Debug, Serialize)]34
pub struct Response<T, E> {35
pub ok: bool,36
pub data: Option<T>,37
pub error: Option<E>,38
}40
impl Response<(), ()> {41
pub fn success() -> Result<tide::Body, tide::Error> {42
tide::Body::from_json(&Self { ok: true, data: None, error: None })43
}44
}46
impl<T> Response<T, ()> where T: Serialize {47
pub fn with(data: T) -> Result<tide::Body, tide::Error> {48
tide::Body::from_json(&Self { ok: true, data: Some(data), error: None })49
}50
pub fn with_option(data: Option<T>) -> Result<tide::Body, tide::Error> {51
tide::Body::from_json(&Self { ok: true, data, error: None })52
}53
}56
impl<E> Response<(), E> where E: Serialize {57
pub fn throw(error: E) -> Result<tide::Body, tide::Error> {58
tide::Body::from_json(&Self { ok: false, data: None, error: Some(error) })59
}60
}