xx
A collection of useful Rust macros and small utility functions to make common tasks easier.
Installation
Add this to your Cargo.toml:
[]
= "2.1"
Features
The library provides several optional features that can be enabled as needed:
archive- Archive extraction support (tar.gz, tar.bz2, tar.xz, zip, gzip)glob- File globbing supporthash- SHA256 hashing utilitieshttp- HTTP client functionalityfslock- File system locking
Enable features in your Cargo.toml:
[]
= { = "2.1", = ["archive", "glob", "hash"] }
Modules
Core Modules (Always Available)
file- Enhanced file operations with better error handlingprocess- Process execution utilitiesgit- Git repository operationsenv- Environment variable parsing utilitiescontext- Context management utilitieserror- Error types and result helpers
Optional Modules
archive- Archive extraction (requiresarchivefeature)hash- SHA256 hashing (requireshashfeature)http- HTTP client (requireshttpfeature)fslock- File locking (requiresfslockfeature)
Examples
File Operations
use file;
// Read and write files
let content = read_to_string?;
write?;
// Append to files
append?;
// Directory operations
mkdirp?;
copy_dir_all?;
assert!;
// Find executables
if let Some = which
Environment Variables
use env;
// Parse boolean environment variables
if var_is_true
// Parse paths with tilde expansion
if let Some = var_path
// Parse numeric values
let threads = var_u32.unwrap_or;
let timeout = var_i64.unwrap_or;
Process Execution
use process;
// Run shell commands
let output = sh?;
// Build and run commands
let result = cmd
.read?;
Git Operations
use ;
// Clone a repository
let opts = default.branch;
let repo = clone?;
// Work with existing repository
let git = new;
let branch = git.current_branch?;
let sha = git.current_sha?;
License
MIT - See LICENSE for details
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.