A declarative macro library for Rust that accelerates development by providing ergonomic, compile-time code generation for common tasks—from I/O and control flow to system introspection and shell integration.
AK-Macros is an open-source Rust crate that exposes a curated set of procedural-style macros for everyday development. By moving repetitive patterns into macros, the library reduces boilerplate, improves readability, and keeps your codebase expressive without sacrificing Rust’s safety or performance.
- Metaprogramming — Generate code at compile time from concise patterns.
- Domain-specific ergonomics — Terse, intent-revealing syntax for I/O, conditionals, and loops.
- Consistency — Standardized patterns for printing, prompts, file operations, and shell commands.
- Zero-cost abstraction — Macros expand to straightforward Rust; no runtime overhead beyond what you’d write by hand.
| Area | Capabilities |
|---|---|
| I/O & CLI | akp!, input_prompt!, terminal! — print, prompt, and run shell commands |
| Control flow | if_cond!, use_loop!, use_loopAt! — conditional and iterative logic |
| Filesystem | remove_folder!, remove_file!, remove_all_folders!, use_createFile! |
| Strings & numbers | set_String!, use_upper_case!, use_lower_case!, Positive_number!, Negative_number! |
| System | this_OS!, this_month!, this_year!, Ram_size!, Get_CPU! (Linux) |
| Integration | open_Web! — open URLs in the default browser (cross-platform) |
Optional features (require adding dependencies to your Cargo.toml):
use_rand!— random number generation (rand)use_fetch!— HTTP requests (reqwest,tokio,serde,serde_json)use_zip!— ZIP extraction (zip-extract)
Add to your Cargo.toml:
[dependencies]
ak_macros = "0.2"For optional macros, uncomment or add in Cargo.toml as needed:
# rand = "0.8" # for use_rand!
# reqwest = { version = "0.12", features = ["json"] }
# tokio = { version = "1", features = ["full"] }
# serde = { version = "1.0", features = ["derive"] }
# serde_json = "1.0"
# zip-extract = "0.1"use ak_macros::*;
fn main() {
let name = "AK-Macros";
akp!("Project: {}", name);
}use ak_macros::*;
fn main() {
akp!("Hello, world!");
let name = input_prompt!("Enter the name of your favorite crate: ");
if_cond!(
name,
name == "ak-macros",
akp!("AK-Macros makes Rust feel simple."),
akp!("Give AK-Macros a try—you might love it.")
);
}use ak_macros::*;
fn main() {
// On Unix-like systems use "sh"; on Windows use "cmd"
let result = terminal!("sh", "ls");
akp!("{}", result);
// e.g.: Cargo.lock Cargo.toml README.md src target
}| Macro | Purpose |
|---|---|
akp!(...) |
println! shorthand |
input_prompt!(prompt) |
Read a line from stdin after printing prompt |
terminal!(shell, command) |
Run command via shell, return stdout as String |
if_cond!(var, cond, then_branch, else_branch) |
If/else; variants for single-branch and multiple conditions |
use_loop!(run, start, end, var, body) |
for var in start..end { body } with optional execution flag |
use_loopAt!(array, var, body) |
Iterate over an array with a named variable |
remove_folder!(path) |
Remove a directory (non-recursive) |
remove_file!(path) |
Remove a file |
remove_all_folders!(path) |
Remove a directory and its contents recursively |
use_createFile!(name, path, content) |
Create a file with given content |
set_String!(literal) |
String::from(literal) |
use_upper_case!(ident) / use_lower_case!(ident) |
In-place string case conversion |
Positive_number!(n) / Negative_number!(n) |
Validate and use positive/negative numbers (panic on wrong sign) |
this_OS!() |
Current OS identifier |
this_month!() / this_year!() |
Current month/year (from system time) |
open_Web!(url) |
Open url in the default browser |
Ram_size!() |
Total RAM in GB (Linux /proc/meminfo) |
Get_CPU!() |
CPU model string (Linux /proc/cpuinfo) |
use_rand!(var, type?, block) |
Generate random value and run block (requires rand) |
use_fetch!(url, METHOD) |
Async HTTP request (requires reqwest, tokio, etc.) |
use_zip!(zip_path, extract_path) |
Extract a ZIP file (requires zip-extract) |
Full doc comments and examples are available in the crate docs and source.
The following screenshots illustrate the same logic expressed with plain Rust versus AK-Macros.
| Plain Rust | With AK-Macros |
|---|---|
![]() |
![]() |
AK-Macros is open source and we welcome contributions.
- Fork the repository.
- Clone your fork and create a branch (
git checkout -b feature/your-feature). - Implement your change (new macro, fix, or docs) and add or update tests/examples.
- Format & lint:
cargo fmtandcargo clippy. - Commit with clear messages and open a pull request against
main.
- New macros for common patterns (e.g. retries, timeouts, structured logging).
- Cross-platform improvements for
Ram_size!andGet_CPU!(e.g. macOS/Windows). - Better error handling or configurable behavior (e.g. no
panic!where appropriate). - Documentation, examples, and doc-tests.
- Optional feature flags to pull in optional dependencies only when needed.
By contributing, you agree that your work may be distributed under the project’s MIT license.
- Crate: crates.io/crates/ak_macros
- Docs: docs.rs/ak_macros
- Repository: github.com/hamdymohamedak/AK-macro
- Homepage: ak-macros.vercel.app
This project is licensed under the MIT License — see the LICENSE file for details.


