s2n_quic_core/buffer/
error.rs1#[derive(Debug, PartialEq, Eq, Clone, Copy)]
5pub enum Error<E = core::convert::Infallible> {
6 OutOfRange,
8 InvalidFin,
10 ReaderError(E),
12}
13
14impl<E> From<E> for Error<E> {
15 #[inline]
16 fn from(reader: E) -> Self {
17 Self::ReaderError(reader)
18 }
19}
20
21impl Error {
22 #[inline]
24 pub fn mapped<E>(error: Error) -> Error<E> {
25 match error {
26 Error::OutOfRange => Error::OutOfRange,
27 Error::InvalidFin => Error::InvalidFin,
28 Error::ReaderError(_) => unreachable!(),
29 }
30 }
31}
32
33#[cfg(feature = "std")]
34impl<E: std::error::Error> std::error::Error for Error<E> {}
35
36impl<E: core::fmt::Display> core::fmt::Display for Error<E> {
37 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
38 match self {
39 Self::OutOfRange => write!(f, "write extends out of the maximum possible offset"),
40 Self::InvalidFin => write!(
41 f,
42 "write modifies the final offset in a non-compliant manner"
43 ),
44 Self::ReaderError(reader) => write!(f, "the provided reader failed with: {reader}"),
45 }
46 }
47}
48
49#[cfg(feature = "std")]
50impl<E: 'static + std::error::Error + Send + Sync> From<Error<E>> for std::io::Error {
51 #[inline]
52 fn from(error: Error<E>) -> Self {
53 let kind = match &error {
54 Error::OutOfRange => std::io::ErrorKind::InvalidData,
55 Error::InvalidFin => std::io::ErrorKind::InvalidData,
56 Error::ReaderError(_) => std::io::ErrorKind::Other,
57 };
58 Self::new(kind, error)
59 }
60}