A script-like macro toolkit for Rust, designed with production-grade structure.
openMacros v1 is a full reboot of the project with a clean naming contract, predictable macro signatures, and professional project standards.
This release is intentionally breaking. Old macros from 0.x are removed.
- Verb-first names for actions:
say!,ask!,cmd!,open! - Resource-first names for file system:
file_write!,file_rm!,dir_rm!,dir_wipe! - Short utility names for transformations:
upper!,lower!,str_make!,pos!,neg! - Flow macros use explicit script-like form:
when!,repeat!,each! - Smart flow helpers:
retry!,measure_ms!,ensure!
- Any macro that can fail returns
AkResult<_>. - Pure transform/value macros return direct values.
- Conditional/loop macros keep Rust-native block semantics to stay readable and safe.
openMacros/
src/
lib.rs # public crate entry
error.rs # unified error model
core.rs # internal helper runtime
macros/
control.rs # when/repeat/each
io.rs # say/ask
fs.rs # file_* and dir_* macros
system.rs # cmd/open/os/date macros
string.rs # str/upper/lower/pos/neg
tests/
macro_api.rs
examples/
enterprise_job.rs
say!(...)prints likeprintln!.ask!(prompt)returns trimmedString.
when!(cond => { ... })when!(cond => { ... }, else => { ... })repeat!(i in 0 => 10, { ... })each!(item in items, { ... })retry!(3 => cmd!("echo ok"))?retry!(3 => cmd!("echo ok"), delay_ms => 200)?let (value, elapsed_ms) = measure_ms!(cmd!("echo ok"));ensure!(workers > 0, "workers must be positive");
cmd!("ls")runs with default shell (shon Unix,cmdon Windows).cmd!("sh", "ls -la")runs with explicit shell.os!()returns current OS.open!("https://example.com")opens URL in default browser.month_now!(),year_now!()return date values from system time.
file_write!("/tmp/a.txt", "hello")file_rm!("/tmp/a.txt")dir_rm!("/tmp/empty")dir_wipe!("/tmp/non-empty")
str_make!("hello") -> Stringupper!("hello") -> Stringlower!("HELLO") -> Stringpos!(5) -> AkResult<usize>neg!(-3) -> AkResult<isize>
use open_macros::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
say!("Welcome to openMacros v1");
let lang = ask!("Favorite language: ");
when!(lang == "rust" => {
say!("Great choice.");
}, else => {
say!("Give Rust a shot.");
});
repeat!(i in 0 => 3, {
say!("tick {}", i);
});
file_write!("example.txt", "hello from v1")?;
let out = cmd!("echo done")?;
say!("command output: {}", out);
Ok(())
}- Use
examples/enterprise_job.rsas a baseline for automation jobs in large repos. - Keep business rules in normal Rust functions; use openMacros for orchestration and readability.
- Enforce CI quality gates (
fmt,clippy,test) on every pull request.
cd ../AK-Macros-docs
npm install
npm run docs:devBuild static docs:
cd ../AK-Macros-docs
npm run docs:build- No compatibility layer is provided in v1.
- Replace old macro names directly with the new contract above.
- Adopt
Resulthandling for operations that can fail.
cargo fmt --checkcargo clippy --all-targets --all-features -- -D warningscargo test --all-targets
MIT