| Crates.io | neocrates-awss3 |
| lib.rs | neocrates-awss3 |
| version | 0.1.1 |
| created_at | 2025-12-19 15:32:57.290212+00 |
| updated_at | 2025-12-19 15:32:57.290212+00 |
| description | AWS S3 helper crate for neocrates workspace |
| homepage | |
| repository | https://github.com/ooiai/neocrates.git |
| max_upload_size | |
| id | 1995013 |
| size | 81,075 |
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.
Add Neocrates to your Cargo.toml:
[dependencies]
neocrates = "0.1"
[dependencies]
neocrates = { version = "0.1", default-features = false, features = ["awss3", "rediscache", "logger"] }
edition = "2024")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:
neocrates = { version = "0.1", default-features = false, features = ["awss3", "logger"] }
use neocrates::prelude::*;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Initialize logger (requires "logger" feature)
#[cfg(feature = "logger")]
init_logger().await;
// Use S3 client (requires "awss3" feature)
#[cfg(feature = "awss3")]
{
let s3_client = S3Client::new(
"my-bucket",
"us-east-1",
"https://s3.amazonaws.com",
"ACCESS_KEY",
"SECRET_KEY"
).await?;
// Upload object
s3_client.put_object("uploads/file.txt", b"Hello, World!").await?;
}
// Use Redis cache (requires "rediscache" feature)
#[cfg(feature = "rediscache")]
{
let redis_pool = RedisPool::from_env().await?;
let mut conn = redis_pool.get_connection().await?;
// Set and get cache
redis::cmd("SET").arg("key").arg("value").query_async(&mut *conn).await?;
let value: String = redis::cmd("GET").arg("key").query_async(&mut *conn).await?;
}
Ok(())
}
use neocrates::prelude::*;
// Aliyun STS Client
#[cfg(feature = "awssts")]
async fn aliyun_sts_example() -> anyhow::Result<()> {
let aliyun_client = AliyunStsClient::new(
"YOUR_ACCESS_KEY_ID",
"YOUR_ACCESS_KEY_SECRET",
"acs:ram::123456789012:role/my-role",
"session-name"
);
let credentials = aliyun_client.assume_role(3600).await?;
println!("Temporary AK: {}", credentials.access_key_id);
Ok(())
}
// Tencent STS Client
#[cfg(feature = "awssts")]
async fn tencent_sts_example() -> anyhow::Result<()> {
let tencent_client = TencentStsClient::new(
"YOUR_SECRET_ID",
"YOUR_SECRET_KEY",
"ap-guangzhou"
);
let credentials = tencent_client
.get_temp_credentials("my-session", None, Some(7200))
.await?;
Ok(())
}
#[cfg(feature = "dieselhelper")]
use neocrates::dieselhelper;
#[cfg(feature = "dieselhelper")]
async fn database_example() -> anyhow::Result<()> {
// Initialize database pool
let pool = dieselhelper::create_pool("DATABASE_URL").await?;
// Use connection from pool
dieselhelper::with_connection(&pool, |conn| {
// Your database operations here
// Example: User::find_by_id(conn, 1)?
Ok::<(), diesel::result::Error>(())
}).await?;
Ok(())
}
#[cfg(all(feature = "axum", feature = "middleware"))]
use neocrates::{axum, middleware};
#[cfg(all(feature = "axum", feature = "middleware"))]
async fn web_app() -> anyhow::Result<()> {
use axum::{routing::get, Router};
let app = Router::new()
.route("/health", get(|| async { "OK" }))
.layer(middleware::trace_layer()) // Add tracing middleware
.layer(middleware::cors_layer()); // Add CORS middleware
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
axum::serve(listener, app).await?;
Ok(())
}
Instead of using the prelude, you can import modules directly:
For more comprehensive examples covering various use cases, see the USAGE_EXAMPLES.md file.
#[cfg(feature = "awss3")]
use neocrates::awss3::AwsClient;
#[cfg(feature = "rediscache")]
use neocrates::rediscache::RedisPool;
#[cfg(feature = "logger")]
use neocrates::logger;
Neocrates provides two ways to access functionality:
use neocrates::prelude::*;
// S3Client, RedisPool, init_logger, etc.
use neocrates::awss3;
use neocrates::rediscache;
use neocrates::logger;
Many modules support environment-based configuration:
REDIS_URL, REDIS_POOL_SIZEDATABASE_URL, DATABASE_POOL_SIZERUST_LOG, LOG_FORMATFor advanced use cases, most modules accept custom configuration structs:
#[cfg(feature = "rediscache")]
let config = neocrates::rediscache::RedisConfig {
url: "redis://localhost:6379".to_string(),
pool_size: 10,
connection_timeout: std::time::Duration::from_secs(5),
};
let pool = RedisPool::new(config).await?;
# Default (all features)
cargo build -p neocrates
# Selective features
cargo build -p neocrates --no-default-features --features "awss3,rediscache,logger"
# Release build
cargo build --release -p neocrates
# Run all tests
cargo test -p neocrates
# Test specific features
cargo test -p neocrates --features "awss3,rediscache"
cargo clippy -p neocrates -- -D warnings
cargo fmt --check
# Generate local docs
cargo doc -p neocrates --open
# Check documentation links
cargo doc -p neocrates --no-deps
Cargo.tomlLICENSE-MIT, LICENSE-APACHE)# Test publish first
cargo publish -p neocrates --dry-run
# Publish to crates.io
cargo publish -p neocrates --registry crates-io
Cargo.tomlContributions are welcome! Please follow these guidelines:
prelude rather than changing existing APIscargo clippy and cargo fmt before submitting# Clone and setup
git clone https://github.com/ooiai/neocrates.git
cd neocrates
# Build and test
cargo build -p neocrates
cargo test -p neocrates
# Verify publish readiness
cargo publish -p neocrates --dry-run
If you discover a security vulnerability, please contact the maintainers directly.
Neocrates is dual-licensed under:
SPDX-License-Identifier: MIT OR Apache-2.0
Thanks to the Rust community and the authors of the excellent crates we build upon: