diff --git a/nrpc/src/service.rs b/nrpc/src/service.rs index 4237c10..b5f576f 100644 --- a/nrpc/src/service.rs +++ b/nrpc/src/service.rs @@ -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 {