pilota 0.13.0

Pilota is a thrift and protobuf implementation in pure rust with high performance and extensibility.
Documentation
use std::{
    fmt::{self, Display, Formatter},
    io,
};

use faststr::FastStr;

use crate::msg_impl;

#[deprecated(
    since = "0.11.0",
    note = "Please use the `TransportException` instead. This type will be removed in the next release."
)]
pub type TransportError = TransportException;

/// Information about I/O errors.
///
/// This exception does not send across endpoints, so seems that it is
/// not necessary to keep it in sync with other languages.
///
/// This exception is used to wrap I/O errors and provide a human-readable
/// error message cache.
#[derive(Debug)]
pub struct TransportException {
    /// Actual I/O error.
    io_error: io::Error,
    /// Human-readable error message.
    message: FastStr,
}

impl PartialEq for TransportException {
    fn eq(&self, other: &Self) -> bool {
        self.io_error.kind() == other.io_error.kind()
    }
}

impl Eq for TransportException {}

impl TransportException {
    #[inline]
    pub fn io_error(&self) -> &io::Error {
        &self.io_error
    }

    #[inline]
    pub fn message(&self) -> &FastStr {
        &self.message
    }

    #[inline]
    pub fn kind(&self) -> io::ErrorKind {
        self.io_error.kind()
    }

    msg_impl!();
}

impl From<io::Error> for TransportException {
    #[inline]
    fn from(err: io::Error) -> Self {
        let message = FastStr::from_string(err.to_string());
        TransportException {
            io_error: err,
            message,
        }
    }
}

impl Display for TransportException {
    #[inline]
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        write!(f, "{}: {}", self.kind(), self.message())
    }
}

impl std::error::Error for TransportException {
    #[inline]
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        Some(&self.io_error)
    }
}

impl Clone for TransportException {
    fn clone(&self) -> Self {
        Self {
            // TODO: io::Error doesn't support clone, we can only clone in this way now.
            // Investigate how to do this in the future.
            io_error: io::Error::new(self.io_error().kind(), self.io_error().to_string()),
            message: self.message.clone(),
        }
    }
}