#table #macro #cfg #macro-utility #utility

build cfg_table

A simple macro that expands to different values across compilation targets

2 releases (1 stable)

1.0.0 Nov 26, 2021
0.1.1 Sep 23, 2021
0.1.0 Sep 23, 2021

#468 in FFI

Download history 21/week @ 2025-11-12 18/week @ 2025-11-19 34/week @ 2025-11-26 28/week @ 2025-12-03 35/week @ 2025-12-10 34/week @ 2025-12-17 62/week @ 2025-12-24 21/week @ 2025-12-31 3/week @ 2026-01-07 27/week @ 2026-01-14 25/week @ 2026-01-21 32/week @ 2026-01-28 22/week @ 2026-02-04 16/week @ 2026-02-11 43/week @ 2026-02-18 21/week @ 2026-02-25

106 downloads per month
Used in 2 crates (via gmod)

MIT license

9KB
121 lines

crates.io

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

#[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\"?");
    },
};

No runtime deps