Expand description
§xx
A collection of useful Rust macros and small utility functions to make common tasks easier.
This library provides enhanced alternatives to standard library functions with better error messages, additional convenience methods, and commonly needed functionality that’s missing from the standard library.
§Quick Start
Add to your Cargo.toml
:
[dependencies]
xx = "2.1"
§Core Features
- Enhanced file operations - File I/O with better error messages and automatic parent directory creation
- Process execution - Convenient process spawning with builder pattern
- Git operations - High-level git repository management
- Error handling - Improved error types with context
§Optional Features
Enable additional functionality by adding features to your dependency:
[dependencies]
xx = { version = "2.1", features = ["archive", "glob", "hash"] }
Available features:
archive
- Archive extraction (tar.gz, tar.bz2, tar.xz, zip)glob
- File globbing supporthash
- SHA256 hashing utilitieshttp
- HTTP client functionalityfslock
- File system locking
§Examples
§File Operations
use xx::file;
// Read file with enhanced error messages
let content = file::read_to_string("config.toml")?;
// Write file, creating parent directories automatically
file::write("output/data.txt", "Hello, world!")?;
// Create directory and all parents
file::mkdirp("path/to/deep/directory")?;
§Process Execution
use xx::process;
// Run shell command
let output = process::sh("ls -la")?;
// Build and run commands with builder pattern
let result = process::cmd("git", &["status"]).read()?;
§Git Operations
use xx::git::{Git, CloneOptions};
// Clone a repository
let options = CloneOptions::default().branch("main");
let repo = xx::git::clone("https://github.com/user/repo", "/tmp/repo", &options)?;
// Work with existing repository
let git = Git::new("/path/to/repo".into());
let branch = git.current_branch()?;
let sha = git.current_sha()?;
Re-exports§
Modules§
- context
- Context management utilities Context management utilities
- env
- Environment variable parsing utilities Environment variable utilities
- error
- Error types and result helpers Error types and result helpers
- file
- Enhanced file operations with better error handling Enhanced file operations with better error handling
- git
- Git repository operations Git repository operations
- process
- Process execution utilities Process execution utilities