Improve error generation for USDPL

This commit is contained in:
NGnius (Graham) 2025-02-23 20:26:49 -05:00
parent 554cb937a9
commit d07cba6a38

View file

@ -54,6 +54,30 @@ pub enum ServiceError {
}
}
impl ServiceError {
pub fn variant_str(&self) -> &'static str {
match self {
Self::Encode(_) => "encode",
Self::Decode(_) => "decode",
Self::MethodNotFound => "method not found",
Self::ServiceNotFound => "service not found",
Self::Method(_) => "method",
Self::StreamLength { .. } => "stream length",
}
}
pub fn variant(&self) -> u64 {
match self {
Self::Encode(_) => 0b10,
Self::Decode(_) => 0b11,
Self::MethodNotFound => 0b100,
Self::ServiceNotFound => 0b101,
Self::Method(_) => 0b1000,
Self::StreamLength { .. } => 0b10000,
}
}
}
impl std::fmt::Display for ServiceError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {