httlib_protos/encoder/
error.rs

1use std::error;
2use std::fmt;
3use std::io;
4use std::convert;
5
6/// Contains error options that can be encountered while performing the encoding
7/// operations.
8#[derive(Debug, PartialEq)]
9pub enum EncoderError {
10    /// Indicates that the data size limit has been reached.
11    DataOverflow,
12
13    /// Indicates that the encoder encountered an I/O interruption. Interrupted
14    /// operations can typically be retried.
15    Interrupted,
16    
17    /// Indicates that the encoder was unable to proceed due to the key's
18    /// invalid tag number. A tag number must be unique per message and the
19    /// value can be between `1` and `2^29 - 1`.
20    InvalidTag,
21}
22
23impl From<io::Error> for EncoderError {
24    fn from(_err: io::Error) -> Self {
25        Self::Interrupted
26    }
27}
28
29impl From<convert::Infallible> for EncoderError { // until solved: https://github.com/rust-lang/rust/issues/64715
30    fn from(_: convert::Infallible) -> Self {
31        unreachable!()
32    }
33}
34
35impl fmt::Display for EncoderError {
36    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
37        match self {
38            Self::DataOverflow => write!(fmt, "Available data type size exceeded."),
39            Self::Interrupted => write!(fmt, "Write operation interrupted."),
40            Self::InvalidTag => write!(fmt, "Found tag with invalid number."),
41        }
42    }
43}
44
45impl error::Error for EncoderError {}