sheave_core/messages/
inconsistent_command.rs

1use 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};
13use crate::messages::amf::v0::AmfString;
14
15/// An error that some command name differs you expect.
16#[derive(Debug)]
17pub struct InconsistentCommand {
18    expected: AmfString,
19    actual: AmfString
20}
21
22impl InconsistentCommand {
23    /// Constructs this error.
24    pub fn new(expected: AmfString, actual: AmfString) -> Self {
25        Self { expected, actual }
26    }
27}
28
29impl Display for InconsistentCommand {
30    fn fmt(&self, f: &mut Formatter<'_>) -> FormatResult {
31        writeln!(f, "Command name is inconsistent. expected: {}, actual: {}", self.expected, self.actual)
32    }
33}
34
35impl Error for InconsistentCommand {}
36
37/// A utility function of constructing an `InconsistentCommand` error.
38pub fn inconsistent_command(expected: &str, actual: AmfString) -> IOError {
39    IOError::new(
40        ErrorKind::InvalidData,
41        InconsistentCommand {
42            expected: AmfString::from(expected),
43            actual
44        }
45    )
46}