motorcortex-rust 0.5.0

Motorcortex Rust: a Rust client for the Motorcortex Core real-time control system (async + blocking).
Documentation
use crate::msg::StatusCode;
use std::fmt;

/// Error type for all motorcortex-rust operations.
#[derive(Debug)]
pub enum MotorcortexError {
    /// Connection failed (TLS, socket, timeout)
    Connection(String),

    /// Message encoding failed
    Encode(String),

    /// Message decoding failed
    Decode(String),

    /// Parameter path not found in the tree
    ParameterNotFound(String),

    /// Server returned a non-OK status
    Status(StatusCode),

    /// NNG-level I/O failure (send/receive)
    Io(String),

    /// Subscription operation failed
    Subscription(String),
}

impl fmt::Display for MotorcortexError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Connection(msg) => write!(f, "Connection error: {}", msg),
            Self::Encode(msg) => write!(f, "Encode error: {}", msg),
            Self::Decode(msg) => write!(f, "Decode error: {}", msg),
            Self::ParameterNotFound(path) => write!(f, "Parameter not found: {}", path),
            Self::Status(code) => write!(f, "Server status: {:?}", code),
            Self::Io(msg) => write!(f, "I/O error: {}", msg),
            Self::Subscription(msg) => write!(f, "Subscription error: {}", msg),
        }
    }
}

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

impl From<prost::DecodeError> for MotorcortexError {
    fn from(e: prost::DecodeError) -> Self {
        Self::Decode(e.to_string())
    }
}

/// Convenience alias used throughout the library.
pub type Result<T> = std::result::Result<T, MotorcortexError>;