nostd_multipart/error.rs
1use core::fmt;
2
3/// Every failure the crate can report. See `DESIGN.md` §12.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[non_exhaustive]
6pub enum Error {
7 /// The boundary is not 1–70 RFC 2046 `bchars` ending in a non-space byte, the
8 /// `Content-Type` carries no usable `boundary` parameter, or a
9 /// `boundary_from_random` array has an invalid size (rule 1).
10 Boundary,
11 /// A part header line (including its CRLF) is longer than `LINE` (rule 5.1).
12 HeaderTooLong,
13 /// A part has more than `MAX_HEADERS` header lines (rule 5.4).
14 TooManyHeaders,
15 /// A header line is malformed: bare LF, missing colon, empty or non-token name,
16 /// obs-fold, CR inside the line (rule 5); or an encoder content type containing
17 /// CR/LF (§11).
18 Header,
19 /// The input ended before the close delimiter (rule 7).
20 UnexpectedEof,
21 /// A `Content-Disposition` value does not follow RFC 2183 syntax (rule 8).
22 Disposition,
23}
24
25impl fmt::Display for Error {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 f.write_str(match self {
28 Error::Boundary => "invalid multipart boundary",
29 Error::HeaderTooLong => "part header line exceeds LINE",
30 Error::TooManyHeaders => "part has more than MAX_HEADERS headers",
31 Error::Header => "malformed part header line",
32 Error::UnexpectedEof => "input ended before the close delimiter",
33 Error::Disposition => "malformed Content-Disposition value",
34 })
35 }
36}
37
38impl core::error::Error for Error {}