mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-06-01 09:42:41 +00:00
Error handling and better structure
This commit is contained in:
parent
544ce897c5
commit
9ab4b8a7fd
4 changed files with 64 additions and 48 deletions
|
|
@ -3,13 +3,21 @@ use std::fmt::Formatter;
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum GDError {
|
||||
PacketOverflow
|
||||
PacketOverflow(String),
|
||||
PacketUnderflow(String),
|
||||
PacketBad(String),
|
||||
PacketSend(String),
|
||||
PacketReceive(String)
|
||||
}
|
||||
|
||||
impl fmt::Display for GDError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
GDError::PacketOverflow => write!(f, "Packet overflow!")
|
||||
GDError::PacketOverflow(details) => write!(f, "Packet overflow: {details}"),
|
||||
GDError::PacketUnderflow(details) => write!(f, "Packet underflow: {details}"),
|
||||
GDError::PacketBad(details) => write!(f, "Packet bad: {details}"),
|
||||
GDError::PacketSend(details) => write!(f, "Couldn't send a packet: {details}"),
|
||||
GDError::PacketReceive(details) => write!(f, "Couldn't receive a packet: {details}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue