rusmpp_extra/concatenation/
errors.rs

1//! Errors related to concatenated message creation.
2
3use rusmpp_core::types::OctetStringError;
4
5use crate::concatenation::{MAX_PARTS, MIN_PARTS};
6
7/// Errors that can occur during multipart message creation.
8#[derive(Debug, thiserror::Error)]
9#[non_exhaustive]
10pub enum MultipartError<E> {
11    #[error("Concatenation error: {0}")]
12    Concatenation(E),
13    #[error("Encoder produced invalid short message: {0}")]
14    ShortMessage(
15        #[from]
16        #[source]
17        OctetStringError,
18    ),
19    #[error("The number of parts is less than the minimum required. actual: {actual}, min: {min}")]
20    MinPartCount {
21        /// The minimum required number of parts.
22        min: usize,
23        /// The actual number of parts.
24        actual: usize,
25    },
26    #[error("The number of parts exceeds the maximum allowed. actual: {actual}, max: {max}")]
27    MaxPartsCount {
28        /// The maximum allowed number of parts.
29        max: usize,
30        /// The actual number of parts.
31        actual: usize,
32    },
33}
34
35impl<E> MultipartError<E> {
36    pub(crate) const fn concatenation(error: E) -> Self {
37        Self::Concatenation(error)
38    }
39
40    pub(crate) const fn min_part_count(actual: usize) -> Self {
41        Self::MinPartCount {
42            min: MIN_PARTS,
43            actual,
44        }
45    }
46
47    pub(crate) const fn max_parts_count(actual: usize) -> Self {
48        Self::MaxPartsCount {
49            max: MAX_PARTS,
50            actual,
51        }
52    }
53}