uuencoding_multi/error.rs
1/// Errors produced by multi-part UUencoding reassembly.
2///
3/// This enum is `#[non_exhaustive]`; new variants may be added in future
4/// releases without a breaking change.
5///
6/// # Example
7///
8/// ```
9/// use uuencoding_multi::MultiUuError;
10///
11/// let err = MultiUuError::EmptyCollection;
12/// assert!(err.to_string().contains("empty"));
13/// ```
14#[derive(Debug, PartialEq, Eq)]
15#[non_exhaustive]
16pub enum MultiUuError {
17 /// [`reassemble()`][crate::reassemble()] was called on a [`PartCollection`][crate::PartCollection]
18 /// that contains no parts with `part_number >= 1`. A collection that holds
19 /// only a TOC part (`part_number = 0`) triggers this error.
20 EmptyCollection,
21
22 /// A UUdecode error was returned by the `uuencoding` crate while decoding
23 /// one of the part bodies. Reassembly stops at the first failing part.
24 DecodeError(uuencoding::UuError),
25
26 /// Two calls to [`PartCollection::add`][crate::PartCollection::add] provided
27 /// entries with the same `part_number`. The duplicate entry is rejected and
28 /// the collection is left unchanged.
29 DuplicatePart { part_number: u32 },
30}
31
32impl std::fmt::Display for MultiUuError {
33 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 match self {
35 MultiUuError::EmptyCollection => {
36 write!(f, "reassemble() called on empty PartCollection")
37 }
38 MultiUuError::DecodeError(e) => write!(f, "UUdecode error: {}", e),
39 MultiUuError::DuplicatePart { part_number } => {
40 write!(f, "duplicate part number: {}", part_number)
41 }
42 }
43 }
44}
45
46impl std::error::Error for MultiUuError {}
47
48impl From<uuencoding::UuError> for MultiUuError {
49 fn from(e: uuencoding::UuError) -> Self {
50 Self::DecodeError(e)
51 }
52}