diff options
| author | Eskil Queseth <eskilq@kth.se> | 2020-10-16 02:18:59 +0200 |
|---|---|---|
| committer | Eskil Queseth <eskilq@kth.se> | 2020-10-16 02:18:59 +0200 |
| commit | 6a6ee0c9db9de7f7632050ad4984a3f92d8a96e9 (patch) | |
| tree | 61d83227f083c98770677f9cd1a1ea787b2438e4 /mumlib/src | |
| parent | 6136a8d7e9d251348fa514f04d74aa19257c1e18 (diff) | |
| download | mum-6a6ee0c9db9de7f7632050ad4984a3f92d8a96e9.tar.gz | |
add pretty printing for error type
Diffstat (limited to 'mumlib/src')
| -rw-r--r-- | mumlib/src/error.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index 20415b0..cb88aa7 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -1,4 +1,6 @@ use serde::{Serialize, Deserialize}; +use std::fmt::Display; +use serde::export::Formatter; pub type Result<T> = std::result::Result<T, Error>; @@ -6,6 +8,17 @@ pub type Result<T> = std::result::Result<T, Error>; pub enum Error { DisconnectedError, AlreadyConnectedError, - InvalidChannelIdError, - InvalidServerAddrError, + InvalidChannelIdError(u32), + InvalidServerAddrError(String, u16), +} + +impl Display for Error { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + Error::DisconnectedError => write!(f, "Not connected to a server"), + Error::AlreadyConnectedError => write!(f, "Already connected to a server"), + Error::InvalidChannelIdError(id) => write!(f, "Invalid channel id: {}", id), + Error::InvalidServerAddrError(addr, port) => write!(f, "Invalid server address: {}:{}", addr, port), + } + } }
\ No newline at end of file |
