sheave_core/messages/
inconsistent_command.rs

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
use std::{
    error::Error,
    fmt::{
        Display,
        Formatter,
        Result as FormatResult
    },
    io::{
        Error as IOError,
        ErrorKind
    }
};
use crate::messages::amf::v0::AmfString;

/// An error means that some command name differs you expect.
#[derive(Debug)]
pub struct InconsistentCommand {
    expected: AmfString,
    actual: AmfString
}

impl InconsistentCommand {
    /// Constructs this error.
    pub fn new(expected: AmfString, actual: AmfString) -> Self {
        Self { expected, actual }
    }
}

impl Display for InconsistentCommand {
    fn fmt(&self, f: &mut Formatter<'_>) -> FormatResult {
        writeln!(f, "Command name is inconsistent. expected: {}, actual: {}", self.expected, self.actual)
    }
}

impl Error for InconsistentCommand {}

/// A utility function of constructing an `InconsistentCommand` error.
pub fn inconsistent_command(expected: &str, actual: AmfString) -> IOError {
    IOError::new(
        ErrorKind::InvalidData,
        InconsistentCommand {
            expected: AmfString::from(expected),
            actual
        }
    )
}