1use std::{error::Error, fmt, net::SocketAddr};
2
3#[derive(Debug)]
4pub enum NaiaServerError {
5 Message(String),
6 Wrapped(Box<dyn Error>),
7 SendError(SocketAddr),
8 RecvError,
9}
10
11impl NaiaServerError {
12 pub fn from_message(message: &str) -> Self {
13 Self::Message(message.to_string())
14 }
15}
16
17impl fmt::Display for NaiaServerError {
18 fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
19 match self {
20 NaiaServerError::Message(msg) => write!(f, "Naia Server Error: {}", msg),
21 NaiaServerError::Wrapped(boxed_err) => fmt::Display::fmt(boxed_err.as_ref(), f),
22 NaiaServerError::SendError(address) => {
23 write!(f, "Naia Server Error: SendError: {}", address)
24 }
25 NaiaServerError::RecvError => {
26 write!(f, "Naia Server Error: RecvError")
27 }
28 }
29 }
30}
31
32impl Error for NaiaServerError {}
33unsafe impl Send for NaiaServerError {}
34unsafe impl Sync for NaiaServerError {}