rustfm_scrobble_proxy/
error.rs

1use std::error::Error as StdError;
2use std::fmt;
3use std::time::SystemTimeError;
4
5/// Represents an Error that occurred while interacting with the Last.fm API
6/// 
7/// `ScrobblerError` contains an error message, which is set when an error occurs and exposed via Trait standard error
8/// Trait implementations. 
9/// 
10/// Most error handling for clients can operate off the `Ok`/`Err` signaling from the `Result` types of API operations,
11/// however this error type is exposed in case you want to implement more complex error handling.
12#[derive(Debug)]
13pub struct ScrobblerError {
14    err_msg: String,
15}
16
17impl ScrobblerError {
18    pub fn new(err_msg: String) -> Self {
19        ScrobblerError { err_msg }
20    }
21}
22
23impl fmt::Display for ScrobblerError {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25        write!(f, "{}", self.err_msg)
26    }
27}
28
29impl StdError for ScrobblerError {}
30
31impl From<SystemTimeError> for ScrobblerError {
32    fn from(error: SystemTimeError) -> Self {
33        Self::new(error.to_string())
34    }
35}
36
37impl From<String> for ScrobblerError {
38    fn from(error: String) -> Self {
39        Self::new(error)
40    }
41}