#cfg #table #macro #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

#183 in FFI

Download history 4/week @ 2024-01-01 40/week @ 2024-01-08 5/week @ 2024-01-15 7/week @ 2024-01-22 261/week @ 2024-01-29 122/week @ 2024-02-05 23/week @ 2024-02-12 174/week @ 2024-02-19 56/week @ 2024-02-26 116/week @ 2024-03-04 50/week @ 2024-03-11 37/week @ 2024-03-18 98/week @ 2024-03-25 124/week @ 2024-04-01 29/week @ 2024-04-08 24/week @ 2024-04-15

277 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