include_toml!() { /* proc-macro */ }Expand description
Parse Cargo.toml at compile time.
§TOML to Rust conversion
- TOML string -> Rust
&str - TOML integer -> Rust
i64 - TOML float -> Rust
f64 - TOML boolean -> Rust
bool - TOML datetime -> Rust
&str - TOML array -> Rust tuple
TOML arrays can hold different types, RustVecs can’t. - TOML table -> Rust tuple
TOML tables can hold different types, RustVecs can’t.
§Example
Keys to index Cargo.toml are parsed as string literals and array / table indexes are parsed as integer literals:
use include_cargo_toml::include_toml;
assert_eq!(
include_toml!("package"."version"),
"0.1.0"
);
assert_eq!(
include_toml!("package"."name"),
"include-cargo-toml"
);
// indexing array with literal 2
assert_eq!(
include_toml!("package"."keywords".2),
"Cargo-toml"
);
assert_eq!(
include_toml!("lib"."proc-macro"),
true
);Because TOML’s arrays and tables do not work like Vec and HashMap, tuples are used.
use include_cargo_toml::include_toml;
assert_eq!(
include_toml!("package"."keywords"),
("macro", "version", "Cargo-toml", "compile-time", "parse")
);Leading or trailing dots are not allowed:
ⓘ
use include_cargo_toml::include_toml;
let this_fails = include_toml!(."package"."name");
let this_fails_too = include_toml!("package"."name".);