Crates.io | env_id |
lib.rs | env_id |
version | 0.0.1 |
source | src |
created_at | 2023-11-21 06:18:39.523047 |
updated_at | 2023-11-21 06:18:39.523047 |
description | Use environment variables as identifiers. |
homepage | |
repository | https://github.com/MaxXSoft/build_assert |
max_upload_size | |
id | 1043761 |
size | 5,805 |
Use environment variables as identifiers.
Add env_id
to your project by running cargo add
:
cargo add env_id
let env_id!("CARGO_CRATE_NAME") = 1;
dbg!(env_id!("CARGO_CRATE_NAME"));
Or you can provide a default value:
let env_id!("HELLO" ?: hello) = 1;
dbg!(env_id!("HELLO" ?: hello));
This may be useful when you want to let users specify the name of a public item, but the following code doesn't compile:
pub const env_id!("HELLO" ?: hello): usize = 1;
You can use another macro to do the same thing:
macro_rules! def_const {
($id:ident) => {
pub const $id: usize = 1;
};
}
env_id!("HELLO"?: hello => def_const);
Copyright (C) 2023 MaxXing. Licensed under either of Apache 2.0 or MIT at your option.