rusmpp_extra/encoding/latin1/
errors.rs

1use crate::concatenation::MAX_PARTS;
2
3/// Errors that can occur during Latin1 encoding.
4
5#[derive(Debug, thiserror::Error, PartialEq, Eq)]
6pub enum Latin1EncodeError {
7    /// Input contains un-encodable character.
8    #[error("Input contains un-encodable character")]
9    UnencodableCharacter,
10}
11
12/// Errors that can occur during Latin1 concatenation.
13#[derive(Debug, thiserror::Error, PartialEq, Eq)]
14pub enum Latin1ConcatenateError {
15    /// Encoding error.
16    #[error("Encoding error: {0}")]
17    Encode(
18        #[from]
19        #[source]
20        Latin1EncodeError,
21    ),
22    /// Part cannot fit even a single character.
23    ///
24    /// This error is returned when `max_message_size - part_header_size == 0`.
25    #[error(
26        "Cannot fit even a single character into a part with the given header and size constraints"
27    )]
28    PartCapacityExceeded,
29    #[error("The number of parts exceeds the maximum allowed. actual: {actual}, max: {max}")]
30    /// The number of parts exceeds the maximum allowed.
31    PartsCountExceeded {
32        /// The maximum allowed number of parts.
33        max: usize,
34        /// The actual number of parts.
35        actual: usize,
36    },
37}
38
39impl Latin1ConcatenateError {
40    pub(crate) const fn parts_count_exceeded(actual: usize) -> Self {
41        Self::PartsCountExceeded {
42            max: MAX_PARTS,
43            actual,
44        }
45    }
46}