Neocrates
A comprehensive Rust library providing unified access to essential utilities for web development, AWS integration, database operations, caching, and more. Neocrates acts as a facade crate that re-exports functionality from multiple internal modules while offering a curated prelude for convenient imports.
- δΈζζζ‘£: README.zh-CN.md
π Features
- Unified Interface: Single dependency for multiple capabilities
- Modular Design: Enable only what you need with feature flags
- AWS Integration: S3 and STS clients for Aliyun/Tencent Cloud
- Database Helpers: Diesel integration with connection pooling
- Caching: Redis connection pool and cache utilities
- Web Utilities: Logging, middleware, response handling, and validation
- Security: Cryptographic utilities and SMS functionality
- Zero Cost: Unused features don't add to your binary size
π¦ Installation
Add Neocrates to your Cargo.toml:
Full Feature Set (Recommended for getting started)
[]
= "0.1"
Selective Features (Recommended for production)
[]
= { = "0.1", = false, = ["awss3", "rediscache", "logger"] }
Minimum Supported Rust Version (MSRV)
- Rust 1.84+ (uses
edition = "2024")
π§ Feature Flags
Neocrates uses feature flags to keep your dependencies lean. All features are enabled by default via the full feature.
| Feature | Description | Dependencies |
|---|---|---|
awss3 |
S3 client utilities | aws-sdk-s3, aws-config |
awssts |
STS clients (Aliyun/Tencent) | aws-sdk-sts, hmac, sha2 |
crypto |
Cryptography helpers | openssl, ring, argon2 |
dieselhelper |
Diesel database helpers | diesel, deadpool-diesel |
helper |
Common utilities | serde, validator, uuid |
logger |
Tracing-based logger | tracing, tracing-subscriber |
middleware |
Web middlewares | axum, tower-http |
rediscache |
Redis cache utilities | redis, bb8-redis, moka |
response |
Response types | axum, serde_json |
sms |
SMS utilities | reqwest, hmac, sha2 |
full |
All features above | - |
Disable default features:
= { = "0.1", = false, = ["awss3", "logger"] }
π― Usage Examples
Basic Setup with Prelude
use *;
async
AWS STS Clients
use *;
// Aliyun STS Client
async
// Tencent STS Client
async
Database Operations
use dieselhelper;
async
Web Application with Middleware
use ;
async
Direct Module Usage (Alternative)
Instead of using the prelude, you can import modules directly:
For more comprehensive examples covering various use cases, see the USAGE_EXAMPLES.md file.
use AwsClient;
use RedisPool;
use logger;
ποΈ Module Structure
Neocrates provides two ways to access functionality:
1. Curated Prelude (Recommended)
- Stable, commonly-used aliases
- Reduced namespace pollution
- Easy migration path
use *;
// S3Client, RedisPool, init_logger, etc.
2. Namespaced Modules (Full Control)
- Complete access to all functionality
- Clear module boundaries
- No ambiguity in imports
use awss3;
use rediscache;
use logger;
βοΈ Configuration
Environment Variables
Many modules support environment-based configuration:
- Redis:
REDIS_URL,REDIS_POOL_SIZE - Database:
DATABASE_URL,DATABASE_POOL_SIZE - Logging:
RUST_LOG,LOG_FORMAT - AWS: Standard AWS environment variables
Custom Configuration
For advanced use cases, most modules accept custom configuration structs:
let config = RedisConfig ;
let pool = new.await?;
π οΈ Development Commands
Build
# Default (all features)
# Selective features
# Release build
Test
# Run all tests
# Test specific features
Lint
Documentation
# Generate local docs
# Check documentation links
π€ Publishing (For Maintainers)
Prerequisites
- Complete package metadata in
Cargo.toml - Valid license files (
LICENSE-MIT,LICENSE-APACHE) - Clean git repository (no uncommitted changes)
Publish Sequence
# Test publish first
# Publish to crates.io
Version Management
- Follow Semantic Versioning (SemVer)
- Update version in workspace root
Cargo.toml - Consider breaking changes when modifying public APIs
π Documentation
- API Reference: docs.rs/neocrates
- Source Code: GitHub Repository
- Package: crates.io/neocrates
π€ Contributing
Contributions are welcome! Please follow these guidelines:
- API Stability: Prefer adding to
preluderather than changing existing APIs - Feature Flags: New functionality should be behind feature flags when possible
- Testing: Include tests for new features
- Documentation: Update README and add doc comments
- Code Quality: Run
cargo clippyandcargo fmtbefore submitting
Development Workflow
# Clone and setup
# Build and test
# Verify publish readiness
π‘οΈ Security
- Credentials: Never hardcode secrets in code or examples
- Dependencies: Keep dependencies updated to address security vulnerabilities
- Principle of Least Privilege: Use minimal permissions for AWS roles and database users
- Input Validation: Always validate and sanitize user input
If you discover a security vulnerability, please contact the maintainers directly.
π License
Neocrates is dual-licensed under:
- MIT License (LICENSE-MIT)
- Apache License 2.0 (LICENSE-APACHE)
SPDX-License-Identifier: MIT OR Apache-2.0
π Acknowledgements
Thanks to the Rust community and the authors of the excellent crates we build upon:
- AWS SDK for Rust
- Axum
- Diesel
- Redis-rs
- Tracing
- And many others!