xtap-core-lib 0.5.1

星TAP实验室通用 Rust 基座:跨平台路径/IO/硬件/MCP HTTP 服务/egui 主题与字体(features 按需裁剪)
Documentation
use thiserror::Error;

#[derive(Error, Debug)]
pub enum CoreError {
    #[error("IO 错误: {0}")]
    Io(#[from] std::io::Error),

    #[error("路径不存在: {0}")]
    PathNotFound(String),

    #[error("权限不足: {0}")]
    PermissionDenied(String),

    #[error("系统错误: {0}")]
    SystemError(String),

    #[error("未知错误")]
    Unknown,
}

pub type Result<T> = std::result::Result<T, anyhow::Error>;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_display_path_not_found() {
        let e = CoreError::PathNotFound("/tmp/missing".into());
        assert_eq!(e.to_string(), "路径不存在: /tmp/missing");
    }

    #[test]
    fn test_display_unknown() {
        assert_eq!(CoreError::Unknown.to_string(), "未知错误");
    }

    #[test]
    fn test_io_from_conversion() {
        let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file gone");
        let e: CoreError = io_err.into();
        assert!(matches!(e, CoreError::Io(_)));
        assert!(e.to_string().starts_with("IO 错误"));
    }
}