Thanks to visit codestin.com
Credit goes to lib.rs

39 releases (24 stable)

Uses new Rust 2024

2.3.0 Dec 18, 2025
2.2.0 Aug 18, 2025
2.1.3 Sep 20, 2025
2.1.1 May 15, 2025
0.1.4 Sep 23, 2018

#82 in Filesystem

Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

9,161 downloads per month
Used in 13 crates (7 directly)

MIT license

105KB
2K SLoC

xx

Crates.io Documentation License: MIT

A collection of useful Rust macros and small utility functions to make common tasks easier.

Installation

Add this to your Cargo.toml:

[dependencies]
xx = "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 support
  • hash - SHA256 hashing utilities
  • http - HTTP client functionality
  • fslock - File system locking

Enable features in your Cargo.toml:

[dependencies]
xx = { version = "2.1", features = ["archive", "glob", "hash"] }

Modules

Core Modules (Always Available)

  • file - Enhanced file operations with better error handling
  • process - Process execution utilities
  • git - Git repository operations
  • env - Environment variable parsing utilities
  • context - Context management utilities
  • error - Error types and result helpers

Optional Modules

  • archive - Archive extraction (requires archive feature)
  • hash - SHA256 hashing (requires hash feature)
  • http - HTTP client (requires http feature)
  • fslock - File locking (requires fslock feature)

Examples

File Operations

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());
}

Environment Variables

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);

Process Execution

use xx::process;

// Run shell commands
let output = process::sh("ls -la")?;

// Build and run commands
let result = process::cmd("git", &["status"])
    .read()?;

Git Operations

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()?;

License

MIT - See LICENSE for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Dependencies

~6–44MB
~634K SLoC