Skip to main content

nerve_ipc/
error.rs

1//! Protocol-level error types for NERVE.
2//!
3//! `ProtocolError` wraps `ProtocolErrorKind` for local handling.
4//! In v0.1.0, errors are not transmitted over the wire; callers
5//! should log and close the connection on violations.
6
7use crate::types::ProtocolErrorKind;
8use std::fmt;
9
10/// A protocol-level error.
11///
12/// Indicates a violation of the NERVE protocol or an unrecovered framing
13/// issue.  In v0.1.0, protocol errors are not sent over the wire; the
14/// caller is expected to log and close the connection.
15#[derive(Debug, Clone, PartialEq, Eq, Hash)]
16pub struct ProtocolError {
17    kind: ProtocolErrorKind,
18}
19
20impl ProtocolError {
21    /// Creates a new `ProtocolError` of the given kind.
22    #[must_use]
23    #[inline]
24    pub fn new(kind: ProtocolErrorKind) -> Self {
25        Self { kind }
26    }
27
28    /// Returns the kind of this protocol error.
29    #[must_use]
30    #[inline]
31    pub fn kind(&self) -> ProtocolErrorKind {
32        self.kind
33    }
34}
35
36impl fmt::Display for ProtocolError {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        write!(f, "NERVE ProtocolError: {:?}", self.kind)
39    }
40}
41
42impl std::error::Error for ProtocolError {}