sheave_core/byte_buffer/
insufficient_buffer_length.rs1use std::{
2    error::Error,
3    fmt::{
4        Display,
5        Formatter,
6        Result as FormatResult
7    },
8    io::{
9        Error as IOError,
10        ErrorKind
11    }
12};
13
14#[derive(Debug)]
16pub struct InsufficientBufferLength {
17    expected: usize,
18    actual: usize
19}
20
21impl InsufficientBufferLength {
22    pub fn new(expected: usize, actual: usize) -> Self {
24        Self { expected, actual }
25    }
26}
27
28impl Display for InsufficientBufferLength {
29    fn fmt(&self, f: &mut Formatter<'_>) -> FormatResult {
30        writeln!(f, "Buffer length is insufficient. expected: {}, actual: {}", self.expected, self.actual)
31    }
32}
33
34impl Error for InsufficientBufferLength {}
35
36pub fn insufficient_buffer_length(expected: usize, actual: usize) -> IOError {
38    IOError::new(
39        ErrorKind::InvalidInput,
40        InsufficientBufferLength {
41            expected,
42            actual
43        }
44    )
45}