Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/williamvenner/cfg_table
✨ A simple macro that expands to different values across compilation targets
https://github.com/williamvenner/cfg_table
cfg conditional-compilation conditional-compile macro rust
Last synced: 21 days ago
JSON representation
✨ A simple macro that expands to different values across compilation targets
- Host: GitHub
- URL: https://github.com/williamvenner/cfg_table
- Owner: WilliamVenner
- License: mit
- Created: 2021-09-23T23:07:53.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-11-26T18:50:47.000Z (about 3 years ago)
- Last Synced: 2024-10-11T11:33:56.484Z (3 months ago)
- Topics: cfg, conditional-compilation, conditional-compile, macro, rust
- Language: Rust
- Homepage: https://crates.io/crates/cfg_table
- Size: 5.86 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![crates.io](https://img.shields.io/crates/v/cfg_table.svg)](https://crates.io/crates/cfg_table)
# ✨ `cfg_table`
A simple macro that expands to different values across compilation targets.
## Panics
This macro will panic at runtime if no matching value is found.
## Example
```rust
#[macro_use] extern crate cfg_table;let var = cfg_table! {
[all(target_os = "freebsd", target_pointer_width = "64", feature = "my-feature")] => 1337, // custom// common platforms
win32 => 32,
win64 => 64,
linux32 => 32,
linux64 => 64,
macos32 => 32,
macos64 => 64,// pointer widths
32 => 1985,
"32" => 1985,
64 => 2003,
"64" => 2003,_ => 123, // default value if nothing matches, this must be at the bottom
};cfg_table! {
win32 => {
println!("You're on Windows 32-bit!");
},win64 => {
println!("You're on Windows 64-bit!");
},_ => {
panic!("What the heck is a \"Linux\"?");
},
};
```