Skip to main content

kcp_io/
lib.rs

1//! # kcp-io
2//!
3//! A Rust wrapper for the [KCP](https://github.com/skywind3000/kcp) protocol,
4//! providing FFI bindings, a safe API, and async tokio integration.
5//!
6//! ## Features
7//!
8//! - **`kcp-sys`** — Raw FFI bindings to the KCP C library
9//! - **`kcp-core`** — Safe Rust wrapper (implies `kcp-sys`)
10//! - **`kcp-tokio`** — Async tokio integration (implies `kcp-core`, enabled by default)
11//!
12//! ## Quick Start
13//!
14//! ```no_run
15//! use kcp_io::tokio_rt::{KcpStream, KcpSessionConfig};
16//!
17//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
18//! let mut stream = KcpStream::connect("127.0.0.1:8080", KcpSessionConfig::fast()).await?;
19//! stream.send_kcp(b"hello").await?;
20//!
21//! let data = stream.recv_kcp().await?;
22//! println!("Received: {:?}", data);
23//! # Ok(())
24//! # }
25//! ```
26
27// FFI bindings — always compiled (C code is always linked)
28#[cfg(feature = "kcp-sys")]
29pub mod sys;
30
31// Internal sys module (always available for core/tokio, but not public without feature)
32#[cfg(all(not(feature = "kcp-sys"), feature = "kcp-core"))]
33pub(crate) mod sys;
34
35// Safe wrapper
36#[cfg(feature = "kcp-core")]
37pub mod core;
38
39// Async tokio integration
40#[cfg(feature = "kcp-tokio")]
41pub mod tokio_rt;
42
43// Convenience re-exports when kcp-tokio is enabled (default)
44#[cfg(feature = "kcp-tokio")]
45pub use tokio_rt::{KcpListener, KcpSessionConfig, KcpStream, KcpTokioError, KcpTokioResult};
46
47// Convenience re-exports when kcp-core is enabled
48#[cfg(feature = "kcp-core")]
49pub use core::{Kcp, KcpConfig, KcpError, KcpResult};