1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! Error types for the `rlnc-simdx` crate.
/// Errors returned by RLNC operations.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RlncError {
/// `generation_size` or `symbol_size` was zero.
InvalidParameters,
/// A coded packet had wrong coefficient or payload length.
PacketSizeMismatch {
/// Expected coefficient vector length (`generation_size`).
expected_coeffs: usize,
/// Actual coefficient vector length received.
got_coeffs: usize,
/// Expected payload length (`symbol_size`).
expected_payload: usize,
/// Actual payload length received.
got_payload: usize,
},
/// The source slice count does not match `generation_size`.
SourceCountMismatch {
/// Expected number of source symbols.
expected: usize,
/// Actual number of slices provided.
got: usize,
},
/// A source symbol had the wrong byte length.
SourceSizeMismatch {
/// Expected bytes per symbol.
expected: usize,
/// Actual slice length.
got: usize,
},
/// Systematic index out of range.
IndexOutOfRange {
/// Requested systematic symbol index.
index: usize,
/// Exclusive upper bound (`generation_size`).
max: usize,
},
}
impl core::fmt::Display for RlncError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InvalidParameters => {
write!(f, "generation_size and symbol_size must both be > 0")
}
Self::PacketSizeMismatch {
expected_coeffs,
got_coeffs,
expected_payload,
got_payload,
} => write!(
f,
"packet size mismatch: expected ({expected_coeffs} coeffs, {expected_payload} payload), got ({got_coeffs}, {got_payload})"
),
Self::SourceCountMismatch { expected, got } => {
write!(f, "expected {expected} source symbols, got {got}")
}
Self::SourceSizeMismatch { expected, got } => {
write!(
f,
"source symbol size mismatch: expected {expected} bytes, got {got}"
)
}
Self::IndexOutOfRange { index, max } => {
write!(f, "systematic index {index} out of range [0, {max})")
}
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for RlncError {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn display_variants_non_empty() {
let samples = [
RlncError::InvalidParameters,
RlncError::PacketSizeMismatch {
expected_coeffs: 4,
got_coeffs: 2,
expected_payload: 8,
got_payload: 1,
},
RlncError::SourceCountMismatch {
expected: 4,
got: 3,
},
RlncError::SourceSizeMismatch {
expected: 16,
got: 8,
},
RlncError::IndexOutOfRange { index: 5, max: 4 },
];
for e in samples {
let s = format!("{e}");
assert!(!s.is_empty(), "empty Display for {e:?}");
}
}
}