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