#parse #cast #env #env-var #compile

macro env-cast

Macro to parse an environment variable to a numeric type at compile time

1 stable release

1.0.0 Feb 15, 2022

#382 in Parser tooling

MIT license

7KB
101 lines

env-cast

MIT license crates.io version CI docs

env_cast! reads an environment variable just like env!("XXX"), but parses it into a specific type.

Supported types are currently i8, u8, i16, u16, i32, u32, i64, u64, f32, f64.

Example

use env_cast::env_cast;
let PKG_MAJOR: u32 = env_cast!("CARGO_PKG_VERSION_MAJOR" as u32);

lib.rs:

env-cast

env_cast!() reads an environment variable just like env!(), but parses it into a specific type.

Supported types are currently i8, u8, i16, u16, i32, u32, i64, u64, f32, f64.

Example

use env_cast::env_cast;
let PKG_MAJOR: u32 = env_cast!("CARGO_PKG_VERSION_MAJOR" as u32);

Dependencies

~1.5MB
~37K SLoC