Expand description
build_const
: crate for creating constants in your build script
The build_const crate exists to help create rust constant files at compile time or in a generating script. It is ultra simple and lightweight, making constant creation a simple matter.
Recommended use: when developing make your constants in build.rs
. Once your constants are
fairly stable create a script instead and have your constants file be generated in either a
single file or an external crate that you can bring in as a dependency.
§Example
Include build_const = VERSION
in your Cargo.toml
file. For no_std
support (macros only)
use default-features = false
.
See ConstWriter
for how to use in a build.rs or script. To then import a “constants.rs” file
created in build.rs
use:
#[macro_use]
extern crate build_const;
build_const!("constants");
println!("VALUE: {}", VALUE);
println!("VALUE: {}", ARRAY);
For writing constants in a script, the macro src_file!
is also provided.
// will write files to `/src/constants.rs`
let mut consts = ConstWriter::from_path(&Path::from(src_file!("constants.rs"))).unwrap();
// ... use consts
Macros§
- build_
const - Shortcut macro which expands to the same module path used in
ConstWriter::for_build(mod_name)
. - src_
file - Macro which returns the path to file in your
src/
directory.
Structs§
- Const
Value Writer - Created from
ConstWriter::finish_dependencies
. See documentation forConstWriter
. - Const
Writer - Primary object used to write constant files.
Functions§
- write_
array - Write an array and return the array’s full type representation.
- write_
array_ raw - Write an array of raw values and return the array’s full type representation.