Crate build_const [] [src]

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

ConstValueWriter

Created from ConstWriter::finish_dependencies. See documentation for ConstWriter.

ConstWriter

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.