| Crates.io | raz-common |
| lib.rs | raz-common |
| version | 0.2.4 |
| created_at | 2025-07-03 15:33:27.952104+00 |
| updated_at | 2025-07-07 09:26:14.148209+00 |
| description | Common utilities and shared types for the raz project |
| homepage | |
| repository | https://github.com/raz-rs/raz |
| max_upload_size | |
| id | 1736408 |
| size | 53,980 |
Common utilities and shared types for the RAZ project ecosystem.
use raz_common::{EnvBuilder, ShellCommand, Result};
// Build environment variables
let env = EnvBuilder::new()
.add("RUST_BACKTRACE", "1")
.add("RUST_LOG", "debug")
.build();
// Execute shell commands safely
let output = ShellCommand::new("cargo")
.arg("test")
.envs(&env)
.execute()?;
// Use common error handling
use raz_common::{CommonError, ErrorContext};
fn process_file(path: &str) -> Result<()> {
std::fs::read_to_string(path)
.context("Failed to read file")?;
Ok(())
}
use raz_common::{EnvParser, EnvBuilder};
// Parse environment strings
let vars = EnvParser::parse("RUST_BACKTRACE=1 RUST_LOG=debug")?;
// Build environment programmatically
let env = EnvBuilder::new()
.add("KEY", "value")
.build();
use raz_common::{CommonError, ErrorContext};
// Add context to errors
let result = std::fs::read("file.txt")
.context("Failed to read configuration")?;
// Create custom errors
let err = CommonError::InvalidInput("Invalid format".to_string());
use raz_common::OutputFormatter;
let formatter = OutputFormatter::new();
formatter.success("Operation completed");
formatter.warning("This might cause issues");
formatter.error("Operation failed");
use raz_common::{Elapsed, TimeUtils};
let elapsed = Elapsed::start();
// ... do work ...
println!("Operation took: {}", elapsed.format());
This crate is used throughout the RAZ ecosystem:
raz-core uses it for error handling and environment managementraz-cli uses it for output formatting and shell commandsraz-validation uses it for error contextsraz-override uses it for time trackingMIT