| Crates.io | juicy-main |
| lib.rs | juicy-main |
| version | 1.0.1 |
| created_at | 2026-01-21 07:42:47.086796+00 |
| updated_at | 2026-01-21 07:45:25.168265+00 |
| description | Zig's juicy main functionality in Rust |
| homepage | |
| repository | https://github.com/justdeevin/juicy-main |
| max_upload_size | |
| id | 2058571 |
| size | 48,773 |
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.
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 pairs1std::env::Vars, an iterator of key-value pairsVec<(String, String)>, a vector of key-value pairsHashMap<String, String>, a hash map of key-value pairsCommand-line arguments can be provided as
&[String], a slice of strings1std::env::Args, an iterator of stringsVec<String>, a vector of stringsclap feature enabled) any struct implementing clap::Parser, which will
automatically be parsedThis inference is based on the identifier of the type, so type aliases or name collisions will cause improper behavior.
#[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.