#embedded #build #const #static #no_std

no-std build build_const

library for creating importable constants from build.rs or a script

4 releases

0.2.1 Apr 13, 2018
0.2.0 May 31, 2017
0.1.1 May 30, 2017
0.1.0 May 29, 2017

#144 in Embedded development

Download history 21340/week @ 2019-12-02 23770/week @ 2019-12-09 20373/week @ 2019-12-16 10705/week @ 2019-12-23 11038/week @ 2019-12-30 19244/week @ 2020-01-06 22680/week @ 2020-01-13 26883/week @ 2020-01-20 23158/week @ 2020-01-27 19366/week @ 2020-02-03 22293/week @ 2020-02-10 20964/week @ 2020-02-17 24858/week @ 2020-02-24 24484/week @ 2020-03-02 22545/week @ 2020-03-09 20742/week @ 2020-03-16

105,935 downloads per month
Used in 183 crates (2 directly)

MIT license

11KB
139 lines

build_const: crate for creating constants in your build script

Rust library for creating importable constants from build.rs or a script

See the crate documentation and the crate on crates.io


lib.rs:

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

No runtime deps