bt_any_error 0.1.0

An easy-to-use, lightweight, zero-dependency generic Error that can be passed to another thread.
Documentation

#[cfg(test)]
mod tests_any_err2 {
    use std::error::Error;
    use bt_any_error::any_err::{AnyErr, IntoAnyErr, StringError};

    /// A simple custom error type.
    #[derive(Debug)]
    struct SimpleError;
    impl std::fmt::Display for SimpleError {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
            write!(f, "simple error")
        }
    }
    impl Error for SimpleError {}

    /// A non-Send error type (contains Rc).
    #[derive(Debug)]
    struct NonSendError(std::rc::Rc<u32>);
    impl std::fmt::Display for NonSendError {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
            write!(f, "non-send error")
        }
    }

    impl Error for NonSendError {}

    #[test]
    fn converts_simple_error() {
        let result: Result<(), SimpleError> = Err(SimpleError);
        let converted = result.any();
        assert!(converted.is_err());
    }

    #[test]
    fn converts_boxed_error() {
        let err: Box<dyn Error> = Box::new(SimpleError);
        let result: Result<(), Box<dyn Error>> = Err(err);
        let converted = result.any();
        assert!(converted.is_err());
    }

    #[test]
    fn test_string_error_debug_formatting() {
        // 1. Create a dummy non-Send error and convert it
        let original_result:  Result<(), Box<dyn Error>> = Err("database connection timeout".into());
        let converted: Result<(), AnyErr> = original_result.any();
        
        let error = converted.unwrap_err();

        // 2. Format the error using Debug syntax ({:?})
        let debug_output = format!("{:?}", error);

        // 3. Verify it contains the inner message text.
        assert_eq!(debug_output, "database connection timeout",
            "Debug output should include the inner error message"
        );
    }

    #[test]
    fn wraps_non_send_error() {
        let err = NonSendError(std::rc::Rc::new(42));
        let result: Result<(), NonSendError> = Err(err);
        let converted = result.any();
        assert!(converted.is_err());
    }

    #[test]
    fn wrapper_is_send_and_sync() {
        fn assert_send_sync<T: Send + Sync>() {}
        assert_send_sync::<StringError>();
    }

    #[test]
    fn any_err_is_send_and_sync() {
        fn assert_send_sync<T: Send + Sync>() {}
        assert_send_sync::<AnyErr>();
    }


    #[test]
    fn any_method_allows_question_mark() {
        fn test_fn() -> Result<(), AnyErr> {
            let result: Result<(), SimpleError> = Err(SimpleError);
            result.any()?; // should compile and run
            Ok(())
        }

        let out = test_fn();
        assert!(out.is_err());
    }
}