toml_const
TOML compile-time constants
Getting started
use ;
// workspace root
// ├── example.toml
// ├── toml_const <---- you are here
// │ ├── Cargo.toml
// │ └── src
// └── toml_const_macros
// ├── Cargo.toml
// └── src
// include a TOML file in your project relative to your manifest directory
toml_const!
// include a file relative to your workspace root
toml_const_ws!
// table keys are capitalized struct fields
const TITLE: &str = EXAMPLE_TOML.TITLE;
assert_eq!;
Table substitution
File substitution is supported. The first path that exists and satisfies the following conditions will be used. These conditions are, in order of precedence:
- if a substitute path has the
usekeyword prefixed - iif a toml file contains
use = trueat the root level
Multiple substitute files can be specified in the macro expression.
The first file containing a use = true key will be merged into the parent file.
These files may contain secrets or other sensitive information that you don't want to check into version control.
use toml_const;
toml_const!
Limitations
This library does not support the full TOML specification.
It will fail to:
- generate arrays with distinct types (arrays containing different types, arrays of tables with different keys)
- create a struct from a table with a blank key
"" = true
It will modify:
- table keys that begin with numbers
- table keys that contain invalid characters for identifiers
TOML data types
All TOML data types are supported. Datetime related structs are re-exported from toml.
| data type | rust type |
|---|---|
| boolean | bool |
| integer | i64 |
| float | f64 |
| string | &'static str |
| date | toml::value::Datetime |
| array | toml_const::Array<T> |
| table | auto-generated struct |