1 use crate::{CtlType, InPkt, PktType};
2 use num_enum::TryFromPrimitiveError;
4 use tokio::sync::mpsc::error::SendError;
14 InvalidChunkIndex(usize, usize),
15 InvalidChunkCount(usize, usize),
20 impl From<io::Error> for Error {
21 fn from(err: io::Error) -> Self {
26 impl From<TryFromPrimitiveError<PktType>> for Error {
27 fn from(err: TryFromPrimitiveError<PktType>) -> Self {
28 Self::InvalidType(err.number)
32 impl From<TryFromPrimitiveError<CtlType>> for Error {
33 fn from(err: TryFromPrimitiveError<CtlType>) -> Self {
34 Self::InvalidType(err.number)
38 impl From<SendError<InPkt>> for Error {
39 fn from(_err: SendError<InPkt>) -> Self {
44 impl fmt::Display for Error {
45 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50 IoError(err) => write!(f, "IO error: {}", err),
51 InvalidProtoId(id) => write!(f, "invalid protocol ID: {id}"),
52 InvalidChannel(ch) => write!(f, "invalid channel: {ch}"),
53 InvalidType(tp) => write!(f, "invalid type: {tp}"),
54 InvalidCtlType(tp) => write!(f, "invalid control type: {tp}"),
55 PeerIDAlreadySet => write!(f, "peer ID already set"),
56 InvalidChunkIndex(i, n) => write!(f, "chunk index {i} bigger than chunk count {n}"),
57 InvalidChunkCount(o, n) => write!(f, "chunk count changed from {o} to {n}"),
58 RemoteDisco(to) => write!(
60 "remote disconnected{}",
61 if *to { " (timeout)" } else { "" }
63 LocalDisco => write!(f, "local disconnected"),