MpdError: impl thiserror
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
// See https://github.com/MusicPlayerDaemon/MPD/blob/7774c3369e1484dc5dec6d7d9572e0a57e9c5302/src/command/AllCommands.cxx#L67-L209
|
||||
pub type Response = Result<(), MpdError>;
|
||||
@@ -23,10 +26,20 @@ pub enum ErrorCode {
|
||||
Exist = 56,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Error, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct MpdError {
|
||||
code: ErrorCode,
|
||||
command: String,
|
||||
message: String,
|
||||
command_list_num: usize,
|
||||
}
|
||||
|
||||
impl Display for MpdError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"MPD Error (code: {:?}, command: '{}', message: '{}', command_list_num: {})",
|
||||
self.code, self.command, self.message, self.command_list_num
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user