nerve-ipc 0.2.0

Binary framing protocol for local IPC over Unix Domain Sockets
Documentation
//! Protocol-level error types for NERVE.
//!
//! `ProtocolError` wraps `ProtocolErrorKind` for local handling.
//! In v0.1.0, errors are not transmitted over the wire; callers
//! should log and close the connection on violations.

use crate::types::ProtocolErrorKind;
use std::fmt;

/// A protocol-level error.
///
/// Indicates a violation of the NERVE protocol or an unrecovered framing
/// issue.  In v0.1.0, protocol errors are not sent over the wire; the
/// caller is expected to log and close the connection.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ProtocolError {
    kind: ProtocolErrorKind,
}

impl ProtocolError {
    /// Creates a new `ProtocolError` of the given kind.
    #[must_use]
    #[inline]
    pub fn new(kind: ProtocolErrorKind) -> Self {
        Self { kind }
    }

    /// Returns the kind of this protocol error.
    #[must_use]
    #[inline]
    pub fn kind(&self) -> ProtocolErrorKind {
        self.kind
    }
}

impl fmt::Display for ProtocolError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "NERVE ProtocolError: {:?}", self.kind)
    }
}

impl std::error::Error for ProtocolError {}