juicy-main

Crates.iojuicy-main
lib.rsjuicy-main
version1.0.1
created_at2026-01-21 07:42:47.086796+00
updated_at2026-01-21 07:45:25.168265+00
descriptionZig's juicy main functionality in Rust
homepage
repositoryhttps://github.com/justdeevin/juicy-main
max_upload_size
id2058571
size48,773
Devin Droddy (justDeeevin)

documentation

README

juicy-main

Juicy fn main in rust.

Inspired by Zig's juicy main functionality, this crate provides an attribute to allow the main function of a binary crate to have input parameters for environment variables and command-line arguments.

Usage

Adding the juicy attribute to fn main will allow the function to accept up to two parameters. Whether each parameter is for env vars or args is inferred from their types.

Environment variables can be provided as

  • &[(String, String)], a slice of key-value pairs1
  • std::env::Vars, an iterator of key-value pairs
  • Vec<(String, String)>, a vector of key-value pairs
  • HashMap<String, String>, a hash map of key-value pairs

Command-line arguments can be provided as

  • &[String], a slice of strings1
  • std::env::Args, an iterator of strings
  • Vec<String>, a vector of strings
  • (with the clap feature enabled) any struct implementing clap::Parser, which will automatically be parsed

This inference is based on the identifier of the type, so type aliases or name collisions will cause improper behavior.

Example

#[juicy_main::juicy]
fn main(env: HashMap<String, String>, args: Vec<String>) {
    dbg!(env);
    eprintln!("executable: {}", args[0]);
}

There is an example using clap in the examples directory.

Footnotes

  1. This doesn't avoid allocations, merely providing a reference to an obscured collected Vec. 2

Commit count: 0

cargo fmt