use core::fmt;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum RpcErrorCode {
FormatViolation,
GenericError,
InternalError,
MessageTypeNotSupported,
NotImplemented,
NotSupported,
OccurrenceConstraintViolation,
PropertyConstraintViolation,
ProtocolError,
RpcFrameworkError,
SecurityError,
TypeConstraintViolation,
#[serde(other)]
Unknown,
}
impl RpcErrorCode {
#[must_use]
pub const fn as_str(&self) -> &'static str {
match self {
Self::FormatViolation => "FormatViolation",
Self::GenericError => "GenericError",
Self::InternalError => "InternalError",
Self::MessageTypeNotSupported => "MessageTypeNotSupported",
Self::NotImplemented => "NotImplemented",
Self::NotSupported => "NotSupported",
Self::OccurrenceConstraintViolation => "OccurrenceConstraintViolation",
Self::PropertyConstraintViolation => "PropertyConstraintViolation",
Self::ProtocolError => "ProtocolError",
Self::RpcFrameworkError => "RpcFrameworkError",
Self::SecurityError => "SecurityError",
Self::TypeConstraintViolation => "TypeConstraintViolation",
Self::Unknown => "Unknown",
}
}
#[must_use]
pub const fn is_deprecated(&self) -> bool {
matches!(self, Self::MessageTypeNotSupported)
}
}
impl fmt::Display for RpcErrorCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}