Crates.io | envir_derive |
lib.rs | envir_derive |
version | |
source | src |
created_at | 2022-07-22 10:38:57.762144 |
updated_at | 2024-12-07 13:44:23.883457 |
description | Derive macro for envir crate |
homepage | |
repository | https://github.com/sanpii/envir |
max_upload_size | |
id | 630675 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
These proc macros help you to implement the envir::Serialize
and
envir::Deserialize
traits.
By default, these macro use the uppercase field name as environment variable name.
use envir::Deserialize;
#[derive(envir::Deserialize, Debug)]
struct Config {
home: String,
}
let config = Config::from_env();
dbg!(config);
$ cargo run
[src/main.rs:12] config = Ok(
Config {
home: "/home/sanpi",
}
)
prefix
: sets this attributes to add this prefix at the field name.use envir::Deserialize;
#[derive(envir::Deserialize, Debug)]
#[envir(prefix = "APP_")]
struct Config {
dir: String,
}
let config = Config::from_env();
dbg!(config);
$ export APP_DIR=~/.config/app
$ cargo run
[src/main.rs:12] config = Ok(
Config {
dir: "/home/sanpi/.config/app",
}
)
name
: use this name for the environment variable instead of the name of the
field. If prefix
is defined, it also prepend to this name;export_with
: use this function to export this field. The given function must
be callable as fn (T) -> HashMap<String, String>
;load_with
: use this function to load this field. The given function must
be callable as fn (Hashmap<String, String>) -> envir::Result<T>
;noprefix
: doesn’t add the prefix
for this field;nested
: this field should be de/serialized recursively;skip
: skip this field, don’t load or export it;skip_load
: don’t load this field;skip_export
: don’t export this field;skip_export_if
: call a function to determine whether to export this field or
not. The given function must be callable as fn(&T) -> bool
.use envir::Deserialize;
#[derive(envir::Deserialize, Debug)]
#[envir(prefix = "APP_")]
struct Config {
dir: String,
}
let config = Config::from_env();
dbg!(config);
$ export APP_DIR=~/.config/app
$ cargo run
[src/main.rs:12] config = Ok(
Config {
dir: "/home/sanpi/.config/app",
}
)