tcpclient 2.1.2

Asynchronous tcpclient based on aqueue actor.
Documentation
//! 错误类型定义 / Error type definitions.
//!
//! 提供 crate 统一的错误类型 [`Error`] 和 [`Result`] 别名。
//! Provides the crate-wide error type [`Error`] and [`Result`] alias.

use std::borrow::Cow;
use thiserror::Error;

/// tcpclient 的所有错误类型。
/// All error types for tcpclient.
///
/// 使用 [`thiserror`] 自动派生 `Display` 和 `std::error::Error`。
/// Uses [`thiserror`] to auto-derive `Display` and `std::error::Error`.
///
/// `SendError` 使用 [`Cow<'static, str>`]:静态消息零分配,动态消息才堆分配。
/// `SendError` uses [`Cow<'static, str>`]: zero-allocation for static messages,
/// heap allocation only for dynamic ones.
#[derive(Error, Debug)]
pub enum Error {
    /// 发送失败(已断开连接或缓冲区为空)。
    /// Send failure (disconnected or empty buffer).
    #[error("{0}")]
    SendError(Cow<'static, str>),

    /// I/O 错误,由 `std::io::Error` 自动转换。
    /// I/O error, auto-converted from `std::io::Error`.
    #[error(transparent)]
    IOError(#[from] std::io::Error),

    /// 通用错误,由 `anyhow::Error` 自动转换。
    /// General error, auto-converted from `anyhow::Error`.
    #[error(transparent)]
    General(#[from] anyhow::Error),
}

/// crate 统一的 `Result` 类型别名,默认错误类型为 [`Error`]。
/// Crate-wide `Result` type alias defaulting to [`Error`].
///
/// ```rust
/// use tcpclient::error::Result;
/// ```
pub type Result<T, E = Error> = core::result::Result<T, E>;