1 use crate::{CtlType, InPkt, PktType};
2 use num_enum::TryFromPrimitiveError;
4 use tokio::sync::mpsc::error::SendError;
18 impl From<io::Error> for Error {
19 fn from(err: io::Error) -> Self {
24 impl From<TryFromPrimitiveError<PktType>> for Error {
25 fn from(err: TryFromPrimitiveError<PktType>) -> Self {
26 Self::InvalidType(err.number)
30 impl From<TryFromPrimitiveError<CtlType>> for Error {
31 fn from(err: TryFromPrimitiveError<CtlType>) -> Self {
32 Self::InvalidType(err.number)
36 impl From<SendError<InPkt>> for Error {
37 fn from(_err: SendError<InPkt>) -> Self {
38 Self::LocalDisco // technically not a disconnect but a local drop
42 impl fmt::Display for Error {
43 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45 write!(f, "RUDP Error: ")?;
48 IoError(err) => write!(f, "IO Error: {}", err),
49 InvalidProtoId(id) => write!(f, "Invalid Protocol ID: {id}"),
50 InvalidPeerID => write!(f, "Invalid Peer ID"),
51 InvalidChannel(ch) => write!(f, "Invalid Channel: {ch}"),
52 InvalidType(tp) => write!(f, "Invalid Type: {tp}"),
53 InvalidCtlType(tp) => write!(f, "Invalid Control Type: {tp}"),
54 RemoteDisco => write!(f, "Remote Disconnected"),
55 LocalDisco => write!(f, "Local Disconnected"),