nardol/error/
error_kind.rs

1/// Enum containing all error kinds used in [nardol](crate).
2#[derive(Debug)]
3pub enum ErrorKind {
4    /// Used if [Packet](crate::packet::Packet) size is bigger than
5    /// [MAX_PACKET_SIZE](crate::packet::MAX_PACKET_SIZE).
6    TooBigPacket,
7
8    /// Used if packet kind was not expected or a function or a method was used on wrong
9    /// [PacketKind](crate::packet::PacketKind) variant.
10    InvalidPacketKind,
11    /// Used if fails to recognize [PacketKind](crate::packet::PacketKind).
12    UnknownPacketKind,
13
14    /// Used if serializing struct with [serde] fails.
15    SerializingFailed,
16    /// Used if deserializing struct with [serde] fails.
17    DeserializingFailed,
18
19    /// Used if buffer size is not valid for the operation,
20    ///  usually used in implementations of [`TryFrom<Bytes>`](TryFrom).
21    InvalidBufferSize,
22
23    /// Used if an error occurs during writing to [TcpStream](std::net::TcpStream).
24    WritingToStreamFailed,
25    /// Used if an error occurs during reading from [TcpStream](std::net::TcpStream).
26    ReadingFromStreamFailed,
27
28    /// Used if and error occurs during sending data to the address using an
29    /// [UdpSocket](std::net::UdpSocket)
30    SendingToAddressFailed,
31    /// Used if and error occurs during receiving data from the address using an
32    /// [UdpSocket](std::net::UdpSocket)
33    ReceivingFromAddressFailed,
34
35    /// Used if an error occurs while trying to create a directory.
36    CreatingDirFailed,
37    /// Used if an error occurs while trying to create a file.
38    CreatingFileFailed,
39    /// Used if an error occurs while trying to open a file.
40    OpeningFileFailed,
41    /// Used if an error occurs while trying to write to a file.
42    WritingToFileFailed,
43    /// Used if an error occurs while trying to read from a file.
44    ReadingFromFileFailed,
45
46    /// Used if anything fails to parse.
47    ParsingFailed,
48
49    /// Wrapper around every error not originating from this library,
50    /// used if there is a need to use produced error directly.
51    OtherSource(Box<dyn std::error::Error>),
52}
53
54impl std::fmt::Display for ErrorKind {
55    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56        write!(f, "ErrorKind")
57    }
58}