codecs/decoding/
error.rs

1#![deny(missing_docs)]
2
3use tokio_util::codec::LinesCodecError;
4
5/// An error that occurs while decoding a stream.
6pub trait StreamDecodingError {
7    /// Whether it is reasonable to assume that continuing to read from the
8    /// stream in which this error occurred will not result in an indefinite
9    /// hang up.
10    ///
11    /// This can occur e.g. when reading the header of a length-delimited codec
12    /// failed and it can no longer be determined where the next header starts.
13    fn can_continue(&self) -> bool;
14}
15
16impl StreamDecodingError for LinesCodecError {
17    fn can_continue(&self) -> bool {
18        match self {
19            LinesCodecError::MaxLineLengthExceeded => true,
20            LinesCodecError::Io(error) => error.can_continue(),
21        }
22    }
23}
24
25impl StreamDecodingError for std::io::Error {
26    fn can_continue(&self) -> bool {
27        false
28    }
29}