use std::fmt;
#[allow(clippy::module_name_repetitions)]
#[derive(Debug)]
#[non_exhaustive]
pub enum ProtocolError {
FragmentedControlFrame,
InvalidCloseCode,
InvalidOpcode,
InvalidPayloadLength,
InvalidRsv,
InvalidUtf8,
UnexpectedMaskedFrame,
UnexpectedUnmaskedFrame,
}
impl ProtocolError {
pub(super) const fn as_str(&self) -> &'static str {
match self {
ProtocolError::FragmentedControlFrame => "fragmented control frame",
ProtocolError::InvalidCloseCode => "invalid close code",
ProtocolError::InvalidOpcode => "invalid opcode",
ProtocolError::InvalidPayloadLength => "invalid payload length",
ProtocolError::InvalidRsv => "invalid extension",
ProtocolError::InvalidUtf8 => "invalid utf-8",
ProtocolError::UnexpectedMaskedFrame => "unexpected masked frame",
ProtocolError::UnexpectedUnmaskedFrame => "unexpected unmasked frame",
}
}
}
impl fmt::Display for ProtocolError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl std::error::Error for ProtocolError {}