#env-var #environment #variables #macro #parser

defvar

A macro that makes defining environment variables easy

1 unstable release

0.1.0 Aug 13, 2024

#890 in Configuration

Download history 98/week @ 2024-08-08 27/week @ 2024-08-15 2/week @ 2024-08-22 3/week @ 2024-08-29 6/week @ 2024-09-05 9/week @ 2024-09-12 14/week @ 2024-09-19 23/week @ 2024-09-26 12/week @ 2024-10-03

60 downloads per month
Used in libdebayer

Apache-2.0

5KB
52 lines

Defvar makes defining environment variables easy

Defvar provides a macro for declaring environment variables. It also makes it easy to describe how to parse the value and provide a default.

Usage

use defvar::defvar;
use std::time::Duration;

// Defining simple variables is easy.
defvar! { GREETING: String = "Howdy" }

// The macro supports types other than String.  You can provide your
// own parsing logic.
defvar! { TIMES: usize = 1, or try t => t.parse() }

// Here is a more complicated example.
defvar! { DURATION: Duration = Duration::from_secs(1), or try d => d.parse().map(Duration::from_secs) }

Dependencies

~48KB