| Crates.io | xx |
| lib.rs | xx |
| version | 2.1.3 |
| created_at | 2018-09-22 22:00:57.044198+00 |
| updated_at | 2025-09-20 14:15:02.477591+00 |
| description | A collection of useful Rust macros and small functions. |
| homepage | |
| repository | https://github.com/jdx/xx |
| max_upload_size | |
| id | 86047 |
| size | 181,606 |
A collection of useful Rust macros and small utility functions to make common tasks easier.
Add this to your Cargo.toml:
[dependencies]
xx = "2.1"
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 lockingEnable features in your Cargo.toml:
[dependencies]
xx = { version = "2.1", features = ["archive", "glob", "hash"] }
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 helpersarchive - Archive extraction (requires archive feature)hash - SHA256 hashing (requires hash feature)http - HTTP client (requires http feature)fslock - File locking (requires fslock feature)use xx::file;
// Read and write files
let content = file::read_to_string("config.toml")?;
file::write("output.txt", "Hello, world!")?;
// Append to files
file::append("log.txt", "New log entry\n")?;
// Directory operations
file::mkdirp("path/to/directory")?;
file::copy_dir_all("src_dir", "dest_dir")?;
assert!(file::is_empty_dir("some_dir")?);
// Find executables
if let Some(git) = file::which("git") {
println!("Git found at: {}", git.display());
}
use xx::env;
// Parse boolean environment variables
if env::var_is_true("VERBOSE") {
println!("Verbose mode enabled");
}
// Parse paths with tilde expansion
if let Some(config_dir) = env::var_path("CONFIG_DIR") {
// ~/.config expands to /home/user/.config
}
// Parse numeric values
let threads = env::var_u32("NUM_THREADS").unwrap_or(4);
let timeout = env::var_i64("TIMEOUT_MS").unwrap_or(5000);
use xx::process;
// Run shell commands
let output = process::sh("ls -la")?;
// Build and run commands
let result = process::cmd("git", &["status"])
.read()?;
use xx::git::{Git, CloneOptions};
// Clone a repository
let opts = CloneOptions::default().branch("main");
let repo = xx::git::clone("https://github.com/user/repo", "/tmp/repo", &opts)?;
// Work with existing repository
let git = Git::new("/path/to/repo".into());
let branch = git.current_branch()?;
let sha = git.current_sha()?;
MIT - See LICENSE for details
Contributions are welcome! Please feel free to submit a Pull Request.