dstar_gateway_core/error/
encode.rs

1//! `EncodeError` for fixed-buffer encoders.
2
3/// Errors raised by `encode_*` functions when the supplied output
4/// buffer is too small for the packet they are asked to write.
5#[derive(Debug, Clone, Copy, thiserror::Error, PartialEq, Eq)]
6#[non_exhaustive]
7pub enum EncodeError {
8    /// Output buffer was smaller than the encoded packet length.
9    #[error("output buffer too small: needed {need} bytes, have {have}")]
10    BufferTooSmall {
11        /// How many bytes the encoder needed to write.
12        need: usize,
13        /// How many bytes the buffer can hold.
14        have: usize,
15    },
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21
22    #[test]
23    fn buffer_too_small_display() {
24        let err = EncodeError::BufferTooSmall { need: 32, have: 16 };
25        let s = err.to_string();
26        assert!(s.contains("32"));
27        assert!(s.contains("16"));
28    }
29}