so://phie

verbal

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

blob: 34d0df34f733294cfe587f18ac553315642270ea (1012 bytes)[doc][blame][raw]

1use serde::Serialize;

2use std::fmt;

3

4#[derive(Debug, Clone, Serialize)]

5pub struct Error {

6 message: String,

7}

8

9impl Error {

10 #[must_use]

11 pub fn new(message: &str) -> Self {

12 Self {

13 message: message.into(),

14 }

15 }

16}

17

18impl fmt::Display for Error {

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

20 write!(f, "{}", self.message)

21 }

22}

23

24impl From<std::io::Error> for Error {

25 fn from(err: std::io::Error) -> Self {

26 Self::new(&err.to_string())

27 }

28}

29

30impl From<std::fmt::Error> for Error {

31 fn from(err: std::fmt::Error) -> Self {

32 Self::new(&err.to_string())

33 }

34}

35

36impl From<toml::de::Error> for Error {

37 fn from(err: toml::de::Error) -> Self {

38 Self::new(&err.to_string())

39 }

40}

41

42impl From<sqlx::Error> for Error {

43 fn from(err: sqlx::Error) -> Self {

44 Self::new(&err.to_string())

45 }

46}

47

48impl From<tide::Error> for Error {

49 fn from(err: tide::Error) -> Self {

50 Self::new(&err.to_string())

51 }

52}