jclass 0.1.7

a simple lib for java class file parse or edit
Documentation
use std::fmt::{Debug, Display, Formatter};

#[derive(Debug, Clone)]
pub struct MessageError {
    pub msg: String
}

#[macro_export]
macro_rules! with_message {
    ($result:expr, $msg:expr) => {
        match $result {
            Ok(t) => Ok(t),
            Err(e) => Err(MessageError::new(&format!("{}: {}", $msg, e))),
        }
    };
}

impl MessageError {
    pub fn new(msg: &str) -> MessageError {
        MessageError {
            msg: String::from(msg)
        }
    }
}

impl<T> Into<Result<T>> for MessageError {
    fn into(self) -> Result<T> {
        Err(self)
    }
}

impl Display for MessageError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str(&self.msg)
    }
}

impl std::error::Error for MessageError {

}

pub type Result<T> = core::result::Result<T, MessageError>;
//
// pub trait ToResult<T> {
//     fn with_message(self, msg: &str) -> Result<T>;
// }
//
// impl<T, E: Display> ToResult<T> for core::result::Result<T, E> {
//     #[inline]
//     fn with_message(self, msg: &str) -> Result<T> {
//         match self {
//             Ok(t) => Ok(t),
//             Err(e) => Err(MessageError::new(&format!("{msg}: {e}"))),
//         }
//     }
// }