tipc 0.1.2

Bindings for interoperating with Linux TIPC sockets.
Documentation
use errno::errno;
use std::fmt;

/// Error information about the attempted TIPC operation
/// # Example
/// ```
/// # use errno::{Errno, set_errno};
/// # use tipc::TipcError;
/// set_errno(Errno(113));
///
/// let e = TipcError::new("My error message");
/// assert_eq!(e.code(), 113);
/// assert_eq!(e.description(), "My error message: No route to host");
///```
#[derive(Debug)]
pub struct TipcError {
    code: i32,
    description: String,
}

impl TipcError {
    pub fn new(err_msg: &str) -> Self {
        let e = errno();
        TipcError {
            description: format!("{}: {}", err_msg, e),
            code: e.0,
        }
    }

    pub fn code(&self) -> i32 {
        self.code
    }

    pub fn description(&self) -> &str {
        &self.description
    }
}

impl fmt::Display for TipcError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{} [errno: {}]", self.description, self.code)
    }
}