5 releases
Uses new Rust 2024
| 0.1.4 | Jul 21, 2025 |
|---|---|
| 0.1.3 | May 8, 2025 |
| 0.1.2 | May 8, 2025 |
| 0.1.1 | May 8, 2025 |
| 0.1.0 | May 7, 2025 |
#1550 in Network programming
Used in 17 crates
(6 directly)
220KB
4K
SLoC
Switchy
Feature-gated re-exports of platform-specific implementations for cross-platform compatibility.
Overview
The Switchy package provides:
- Conditional Re-exports: Feature-gated access to platform-specific modules
- Unified Interface: Single import point for cross-platform functionality
- Module Organization: Structured access to async, database, filesystem, and network modules
- Feature Flexibility: Enable only the modules you need
Features
Available Modules
async: Async runtime utilities (viaswitchy_async)async-macros: Async macro utilities (viaswitchy_async_macros)database: Database abstraction layer (viaswitchy_database)database-connection: Database connection management (viaswitchy_database_connection)fs: Filesystem operations (viaswitchy_fs)mdns: mDNS service discovery (viaswitchy_mdns)random: Random number generation (viaswitchy_random)tcp: TCP networking (viaswitchy_tcp)telemetry: Telemetry and monitoring (viaswitchy_telemetry)time: Time utilities (viaswitchy_time)upnp: UPnP device discovery (viaswitchy_upnp)http: HTTP client/server (viaswitchy_httpandswitchy_http_models)
Module Structure
- Individual Features: Each module is behind its own feature flag
- Nested Modules: HTTP module contains both client and models
- Clean Imports: Simple import paths for all functionality
Installation
Add this to your Cargo.toml:
[dependencies]
switchy = { path = "../switchy", features = ["async", "tcp", "http"] }
# Or enable all features
switchy = { path = "../switchy", features = [
"async",
"async-macros",
"database",
"database-connection",
"fs",
"mdns",
"random",
"tcp",
"telemetry",
"time",
"upnp",
"http",
"http-models"
] }
Usage
Async Utilities
// Enable with features = ["async"]
use switchy::unsync;
// Use async utilities
Database Operations
// Enable with features = ["database", "database-connection"]
use switchy::{database, database_connection};
// Use database functionality
Filesystem Operations
// Enable with features = ["fs"]
use switchy::fs;
// Use filesystem operations
Network Operations
// Enable with features = ["tcp", "mdns", "upnp"]
use switchy::{tcp, mdns, upnp};
// Use networking functionality
HTTP Client/Server
// Enable with features = ["http", "http-models"]
use switchy::http;
use switchy::http::models;
// Use HTTP functionality
Telemetry and Monitoring
// Enable with features = ["telemetry"]
use switchy::telemetry;
// Use telemetry functionality
Time Utilities
// Enable with features = ["time"]
use switchy::time;
// Use time utilities
Random Number Generation
// Enable with features = ["random"]
use switchy::random;
// Use random number generation
Feature Flags
async: Enable async runtime utilitiesasync-macros: Enable async macro utilitiesdatabase: Enable database abstraction layerdatabase-connection: Enable database connection managementfs: Enable filesystem operationsmdns: Enable mDNS service discoveryrandom: Enable random number generationtcp: Enable TCP networkingtelemetry: Enable telemetry and monitoringtime: Enable time utilitiesupnp: Enable UPnP device discoveryhttp: Enable HTTP client/serverhttp-models: Enable HTTP model types
Dependencies
This package re-exports functionality from:
switchy_async- Async runtime utilitiesswitchy_async_macros- Async macro utilitiesswitchy_database- Database abstractionswitchy_database_connection- Database connectionsswitchy_fs- Filesystem operationsswitchy_mdns- mDNS service discoveryswitchy_random- Random number generationswitchy_tcp- TCP networkingswitchy_telemetry- Telemetry and monitoringswitchy_time- Time utilitiesswitchy_upnp- UPnP device discoveryswitchy_http- HTTP client/serverswitchy_http_models- HTTP model types
Use Cases
- Cross-platform Applications: Single interface for platform-specific functionality
- Feature-gated Libraries: Enable only needed functionality to reduce binary size
- Modular Architecture: Clean separation of concerns across different domains
- Testing: Easy mocking and testing with feature flags
Dependencies
~0–32MB
~452K SLoC