so://phie

verbal

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]

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}

10

11impl fmt::Display for Server {

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

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

14 }

15}

16

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

18pub struct Database {

19 pub hostname: String,

20 pub port: i32,

21 pub username: String,

22 pub password: String,

23 pub database: String,

24}

25

26impl 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}

35

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

37pub struct Options {

38 pub origin: String,

39}

40

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

42pub struct Config {

43 pub server: Server,

44 pub database: Database,

45 pub options: Options,

46}

47

48impl 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}