cfg_block

A simple library for applying procedural macros to a block, for easier const values and more readable code. Grab the docs here https://docs.rs/cfg_block.

Here's a simple example for defining variables based on platform:

```rs use cfgblock::cfgblock;

cfgblock!{ #[cfg(targetfamily = "unix")] { const PLATFORM: &str = "posix !"; const MYNUMBER: u8 = 5; } #[cfg(targetfamily = "windows")] { const PLATFORM: &str = "window !"; const MYNUMBER: u16 = 20; } #[cfg(targetfamily = "wasm")] { const PLATFORM: &str = "web !"; const MY_NUMBER: i32 = -5; } }

// Assuming this test runs on linux/macos... asserteq!(PLATFORM, "posix !"); asserteq!(MY_NUMBER, 5); ```

The above example demonstrates using #[cfg()], but it should work for any procedural macro. Behind the scenes, it just inserts the macro attribute before every item in the block, and removes the block wrapper.

This macro also supports a simple if/else configuration:

```rs cfgblock!{ if #[cfg(mips)] { const STRA: &str = "where did you get this processor"; const STRB: &str = "mips just makes a good passing doctest"; } else { const STRA: &str = "good!"; const STR_B: &str = "better!"; } }

asserteq(STRA, "good!"); asserteq(STRB, "better!"); ```

Please note that unlike the general syntax, this if/else syntax only works with #[cfg(something)] (it just replaces it with #[cfg(not(something))]).

Links

Link to crates.io page: https://crates.io/crates/cfg_block

Get the docs here: https://docs.rs/cfg_block

Source repository: https://github.com/pluots/cfg_block

If you have any improvements or ideas, feel free to bring them up on the Github page!