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