| Crates.io | toolcraft-s3-kit |
| lib.rs | toolcraft-s3-kit |
| version | 0.2.0 |
| created_at | 2025-08-07 06:33:44.747668+00 |
| updated_at | 2025-08-07 06:33:44.747668+00 |
| description | Toolcraft s3 module |
| homepage | |
| repository | https://github.com/code-serenade/toolcraft.git |
| max_upload_size | |
| id | 1784750 |
| size | 73,182 |
S3-compatible object storage utilities for the toolcraft ecosystem.
Add this to your Cargo.toml:
[dependencies]
toolcraft-s3-kit = "*"
Check the crates.io page for the latest version.
use toolcraft_s3_kit::S3Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create S3 client
let client = S3Client::new(
"http://localhost:9000",
"minioadmin",
"minioadmin",
None, // Optional region
)?;
// List buckets
let buckets = client.list_buckets().await?;
for bucket in buckets {
println!("Bucket: {}", bucket.name);
}
Ok(())
}
The S3Client provides a high-level interface for interacting with S3-compatible storage:
use toolcraft_s3_kit::S3Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = S3Client::new(
"http://localhost:9000",
"minioadmin",
"minioadmin",
None,
)?;
// Create a bucket
client.create_bucket("my-bucket").await?;
// Upload an object
let data = b"Hello, world!";
client.put_object("my-bucket", "hello.txt", data.to_vec()).await?;
// Download an object
let downloaded = client.get_object("my-bucket", "hello.txt").await?;
println!("Downloaded: {}", String::from_utf8_lossy(&downloaded));
// Generate presigned URL
let url = client.presigned_get_object("my-bucket", "hello.txt", 3600).await?;
println!("Presigned URL: {}", url);
Ok(())
}
use toolcraft_s3_kit::S3Client;
let client = S3Client::new(
"https://s3.amazonaws.com",
"your-access-key",
"your-secret-key",
Some("us-east-1"), // Specify region
)?;
The crate provides detailed error types for different failure scenarios:
use toolcraft_s3_kit::{S3Client, error::S3Error};
match client.get_object("bucket", "key").await {
Ok(data) => println!("Success!"),
Err(S3Error::NotFound) => println!("Object not found"),
Err(S3Error::AccessDenied) => println!("Access denied"),
Err(e) => println!("Other error: {}", e),
}
Bucket Operations
create_bucket()list_buckets()delete_bucket()bucket_exists()Object Operations
put_object()get_object()delete_object()list_objects()object_exists()Presigned URLs
presigned_get_object()presigned_put_object()This crate is designed to work seamlessly with other toolcraft components:
// Use with toolcraft-config for configuration management
use toolcraft_config::Config;
use toolcraft_s3_kit::S3Client;
let config = Config::from_file("config.toml")?;
let s3_endpoint = config.get_string("s3.endpoint")?;
let s3_access_key = config.get_string("s3.access_key")?;
let s3_secret_key = config.get_string("s3.secret_key")?;
let client = S3Client::new(&s3_endpoint, &s3_access_key, &s3_secret_key, None)?;
This project is licensed under the MIT License - see the LICENSE file for details.