use super::*; use num_enum::TryFromPrimitiveError; use thiserror::Error; use tokio::sync::mpsc::error::SendError; #[derive(Error, Debug)] pub enum Error { #[error("io error: {0}")] IoError(#[from] std::io::Error), #[error("invalid protocol ID: {0}")] InvalidProtoId(u32), #[error("invalid channel: {0}")] InvalidChannel(u8), #[error("invalid type: {0}")] InvalidType(u8), #[error("invalid control type: {0}")] InvalidCtlType(u8), #[error("peer ID already set")] PeerIDAlreadySet, #[error("chunk index {0} bigger than chunk count {1}")] InvalidChunkIndex(usize, usize), #[error("chunk count changed from {0} to {1}")] InvalidChunkCount(usize, usize), #[error("remote disconnected (timeout = {0})")] RemoteDisco(bool), #[error("local disconnected")] LocalDisco, } impl From> for Error { fn from(err: TryFromPrimitiveError) -> Self { Self::InvalidType(err.number) } } impl From> for Error { fn from(err: TryFromPrimitiveError) -> Self { Self::InvalidCtlType(err.number) } } impl From> for Error { fn from(_err: SendError) -> Self { Self::LocalDisco } }