1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
use serde::{Deserialize, Serialize};
use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum Error {
DisconnectedError,
AlreadyConnectedError,
ChannelIdentifierError(String, ChannelIdentifierError),
InvalidServerAddrError(String, u16),
InvalidUsernameError(String),
InvalidServerPassword,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::DisconnectedError => write!(f, "Not connected to a server"),
Error::AlreadyConnectedError => write!(f, "Already connected to a server"),
Error::ChannelIdentifierError(id, kind) => write!(f, "{}: {}", kind, id),
Error::InvalidServerAddrError(addr, port) => {
write!(f, "Invalid server address: {}: {}", addr, port)
}
Error::InvalidUsernameError(username) => write!(f, "Invalid username: {}", username),
Error::InvalidServerPassword => write!(f, "Invalid server password")
}
}
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum ChannelIdentifierError {
Invalid,
Ambiguous,
}
impl fmt::Display for ChannelIdentifierError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ChannelIdentifierError::Invalid => write!(f, "Invalid channel identifier"),
ChannelIdentifierError::Ambiguous => write!(f, "Ambiguous channel identifier"),
}
}
}
|