Skip to main content

kcp_io/tokio_rt/
error.rs

1//! Error types for async KCP operations.
2//!
3//! Defines [`KcpTokioError`] which covers all failure modes of the async
4//! KCP session layer, and [`KcpTokioResult<T>`] as a convenient type alias.
5
6use thiserror::Error;
7
8/// Error type for async KCP session operations.
9///
10/// Wraps both I/O errors and lower-level [`KcpError`](crate::core::KcpError)s,
11/// plus session-level errors like timeout and connection closure.
12#[derive(Debug, Error)]
13pub enum KcpTokioError {
14    /// An I/O error occurred on the underlying UDP socket.
15    #[error("IO error: {0}")]
16    Io(#[from] std::io::Error),
17    /// An error from the core KCP engine.
18    #[error("KCP error: {0}")]
19    Kcp(#[from] crate::core::KcpError),
20    /// The session timed out due to no data received within the configured timeout period.
21    #[error("session timed out")]
22    Timeout,
23    /// The session has been closed (either locally or by the remote peer).
24    #[error("session closed")]
25    Closed,
26    /// Failed to establish a connection (e.g., address resolution failure).
27    #[error("connection failed: {0}")]
28    ConnectionFailed(String),
29}
30
31/// A convenience type alias for `Result<T, KcpTokioError>`.
32pub type KcpTokioResult<T> = Result<T, KcpTokioError>;