diff options
Diffstat (limited to 'games/rstnode/rst-core/src/error.rs')
-rw-r--r-- | games/rstnode/rst-core/src/error.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/games/rstnode/rst-core/src/error.rs b/games/rstnode/rst-core/src/error.rs new file mode 100644 index 000000000000..38c93bbe823f --- /dev/null +++ b/games/rstnode/rst-core/src/error.rs @@ -0,0 +1,51 @@ +pub use crate::wire::{AuthErr, LobbyErr, MatchErr, RegErr}; +use serde::{Deserialize, Serialize}; +use std::fmt::{self, Display, Formatter}; + +/// A wrapper around the different RST node errors that can occur +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum Error { + /// Failure in the registration process + Register(RegErr), + /// Failure in the authentication process + Auth(AuthErr), + /// Failure handling a lobby + Lobby(LobbyErr), + /// Failure in a match setting + Match(MatchErr), +} + +impl std::error::Error for Error {} + +impl Display for Error { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!(f, "An RST error") + } +} + +/// A RST Node specific error +pub type Result<T> = std::result::Result<T, Error>; + +impl From<RegErr> for Error { + fn from(e: RegErr) -> Self { + Error::Register(e) + } +} + +impl From<AuthErr> for Error { + fn from(e: AuthErr) -> Self { + Error::Auth(e) + } +} + +impl From<LobbyErr> for Error { + fn from(e: LobbyErr) -> Self { + Error::Lobby(e) + } +} + +impl From<MatchErr> for Error { + fn from(e: MatchErr) -> Self { + Error::Match(e) + } +} |