docs.rs failed to build switchy_tcp-0.3.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
switchy_tcp-0.2.0
Switchy TCP
Generic TCP networking abstraction with Tokio and simulator support.
Overview
The TCP package provides:
- Generic TCP Traits: Abstract TCP listener and stream interfaces
- Tokio Integration: Production-ready async TCP networking
- Simulator Support: Mock TCP networking for testing
- Stream Splitting: Read/write half separation for concurrent operations
- Address Handling: Local and peer address access
- Type Safety: Generic traits for different TCP implementations
Features
Generic TCP Interface
- GenericTcpListener: Abstract TCP listener trait
- GenericTcpStream: Abstract TCP stream trait with read/write
- GenericTcpStreamReadHalf: Abstract read-only stream interface
- GenericTcpStreamWriteHalf: Abstract write-only stream interface
Implementation Support
- Tokio TCP: Production async TCP networking
- Simulator TCP: Mock networking for testing and development
- Wrapper Types: Type-safe wrappers for different implementations
Stream Operations
- AsyncRead/AsyncWrite: Tokio async I/O trait implementations
- Stream Splitting: Separate read and write operations
- Address Information: Access to local and peer socket addresses
- Connection Management: Connect, accept, and close operations
Installation
Add this to your Cargo.toml:
[]
= { = "../tcp" }
# With specific features (both enabled by default)
= {
path = "../tcp",
= false,
= ["tokio"] # or ["simulator"]
}
Usage
Basic TCP Server
use ;
use ;
async
async
TCP Client
use TcpStream;
use ;
async
Stream Splitting
use TcpStream;
use ;
async
Generic TCP Usage
use ;
use ;
async
Simulator Mode (Testing)
use ;
async
Generic Traits
GenericTcpListener
use ;
use SocketAddr;
use async_trait;
GenericTcpStream
use ;
use ;
use SocketAddr;
Error Handling
use ;
async
Feature Flags
tokio: Enable Tokio-based TCP implementation (enabled by default)simulator: Enable simulator/mock TCP implementation (enabled by default)
Note: Both features are enabled by default. When both are enabled, the simulator type aliases (TcpListener, TcpStream, etc.) are used. To use Tokio types exclusively, disable default features and enable only tokio.
Type Aliases
When features are enabled, convenient type aliases are available:
// With simulator feature (takes priority when both are enabled)
pub type TcpListener = SimulatorTcpListener;
pub type TcpStream = SimulatorTcpStream;
pub type TcpStreamReadHalf = SimulatorTcpStreamReadHalf;
pub type TcpStreamWriteHalf = SimulatorTcpStreamWriteHalf;
// With tokio feature only (when simulator is disabled)
pub type TcpListener = TokioTcpListener;
pub type TcpStream = TokioTcpStream;
pub type TcpStreamReadHalf = TokioTcpStreamReadHalf;
pub type TcpStreamWriteHalf = TokioTcpStreamWriteHalf;
To access specific implementations when both features are enabled:
use ;
use ;
Dependencies
Core dependencies:
- switchy_async: Async runtime abstraction with I/O, macros, sync, time, and util support
- tokio: Networking primitives (required, with
netfeature) - async-trait: Async trait support
- thiserror: Error handling
- paste: Macro utilities
- log: Logging
Simulator-specific dependencies (when simulator feature is enabled):
- bytes: Byte buffer management
- flume: MPSC channel implementation
- scoped-tls: Thread-local storage for simulator context
Use Cases
- Network Servers: TCP-based server applications
- Client Applications: TCP client connections
- Protocol Implementation: Custom network protocol development
- Testing: Mock network communication in tests
- Cross-platform Networking: Abstract over different TCP implementations
- Microservices: Service-to-service TCP communication