Crate entrypoint

source ·
Expand description

an (opinionated) app wrapper to eliminate main function boilerplate

Eliminate boilerplate by smartly integrating:

  • anyhow: for easy error handling
  • clap: for easy CLI parsing
  • dotenv: for easy environment variable management
  • tracing: for easy logging

In lieu of main(), an entrypoint function is defined.

Perfectly reasonable setup/config is done automagically. More explicitly, the entrypoint function can be written as if:

  • anyhow::Error is ready to propogate
  • CLI have been parsed
  • .dotenv files have already been processed and populated into the environment
  • logging is ready to use

Customization can be achieved by overriding various trait default implementations (or preferably/more-typically by using the provided attribute macros).


use entrypoint::prelude::*;

#[derive(clap::Parser, DotEnvDefault, LoggerDefault, Debug)]
struct Args {}

// this function replaces `main`
fn main(args: Args) -> anyhow::Result<()> {
    // tracing & parsed clap struct are ready-to-use
    debug!("entrypoint input args: {:#?}", args);

    // env vars already have values from dotenv file(s)
    for (key, value) in std::env::vars() {
        println!("{key}: {value}");

    // easy error propagation w/ anyhow

§Feature Flags

macrosEnables optional utility macrosYes