Skip to main content

include_toml

Macro include_toml 

Source
include_toml!() { /* proc-macro */ }
Expand description

Parse Cargo.toml at compile time.

§TOML to Rust conversion

§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".);