so://phie

verbal

A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal

blob: bc2d617c6c3998d11bf706021cc9b26bfb768526 (1207 bytes)[doc][blame][raw]

1use serde::Deserialize;

2use std::fmt;

3use std::fs;

4

5#[derive(Debug, Clone, Deserialize)]

6pub struct Server {

7 pub hostname: String,

8 pub port: i32,

9 pub options: Options,

10}

11

12impl fmt::Display for Server {

13 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

14 write!(f, "{}:{}", self.hostname, self.port,)

15 }

16}

17

18#[derive(Debug, Clone, Deserialize)]

19pub struct Options {

20 pub origin: String,

21}

22

23#[derive(Debug, Clone, Deserialize)]

24pub struct Database {

25 pub hostname: String,

26 pub port: i32,

27 pub username: String,

28 pub password: String,

29 pub database: String,

30}

31

32impl fmt::Display for Database {

33 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

34 write!(

35 f,

36 "postgres://{}:{}@{}:{}/{}?sslmode=disable",

37 self.username, self.password, self.hostname, self.port, self.database,

38 )

39 }

40}

41

42#[derive(Debug, Clone, Deserialize)]

43pub struct Config {

44 pub server: Server,

45 pub database: Database,

46}

47

48impl Config {

49 pub fn from_file(path: &str) -> Result<Self, toml::de::Error> {

50 let raw = fs::read_to_string(path).expect("Unable to locate config.ron file!");

51 toml::from_str(&raw)

52 }

53}