A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 49df4705cfe817f5862abe324e247dbe43312075 (1201 bytes)[doc][blame][raw]
1
use serde::Deserialize;2
use std::fmt;3
use std::fs;5
#[derive(Debug, Clone, Deserialize)]6
pub struct Server {7
pub hostname: String,8
pub port: i32,9
}11
impl fmt::Display for Server {12
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {13
write!(f, "{}:{}", self.hostname, self.port,)14
}15
}17
#[derive(Debug, Clone, Deserialize)]18
pub struct Database {19
pub hostname: String,20
pub port: i32,21
pub username: String,22
pub password: String,23
pub database: String,24
}26
impl fmt::Display for Database {27
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {28
write!(29
f,30
"postgres://{}:{}@{}:{}/{}?sslmode=disable",31
self.username, self.password, self.hostname, self.port, self.database,32
)33
}34
}36
#[derive(Debug, Clone, Deserialize)]37
pub struct Options {38
pub origin: String,39
}41
#[derive(Debug, Clone, Deserialize)]42
pub struct Config {43
pub server: Server,44
pub database: Database,45
pub options: Options,46
}48
impl Config {49
pub fn from_file(path: &str) -> Result<Self, ron::Error> {50
let raw = fs::read_to_string(path).expect("Unable to locate config.ron file!");51
ron::from_str(&raw)52
}53
}