]> git.lizzy.rs Git - mt_rudp.git/blob - src/error.rs
Remove debug print
[mt_rudp.git] / src / error.rs
1 use super::*;
2 use num_enum::TryFromPrimitiveError;
3 use thiserror::Error;
4
5 #[derive(Error, Debug)]
6 pub enum Error {
7     #[error("io error: {0}")]
8     IoError(#[from] std::io::Error),
9     #[error("invalid protocol ID: {0}")]
10     InvalidProtoId(u32),
11     #[error("invalid channel: {0}")]
12     InvalidChannel(u8),
13     #[error("invalid type: {0}")]
14     InvalidType(u8),
15     #[error("invalid control type: {0}")]
16     InvalidCtlType(u8),
17     #[error("peer ID already set")]
18     PeerIDAlreadySet,
19     #[error("chunk index {0} bigger than chunk count {1}")]
20     InvalidChunkIndex(usize, usize),
21     #[error("chunk count changed from {0} to {1}")]
22     InvalidChunkCount(usize, usize),
23     #[error("remote disconnected (timeout = {0})")]
24     RemoteDisco(bool),
25     #[error("local disconnected")]
26     LocalDisco,
27 }
28
29 impl From<TryFromPrimitiveError<PktType>> for Error {
30     fn from(err: TryFromPrimitiveError<PktType>) -> Self {
31         Self::InvalidType(err.number)
32     }
33 }
34
35 impl From<TryFromPrimitiveError<CtlType>> for Error {
36     fn from(err: TryFromPrimitiveError<CtlType>) -> Self {
37         Self::InvalidCtlType(err.number)
38     }
39 }