#language #macro #utility #no-std #rust

no-std ternary-rs

A Rust library for emulating the ternary operator from C/C++ (among other languages)

1 stable release

1.0.0 Jan 15, 2021

#750 in #utility

Download history 57/week @ 2024-03-30 29/week @ 2024-04-06 30/week @ 2024-04-13 24/week @ 2024-04-20 68/week @ 2024-04-27 48/week @ 2024-05-04 81/week @ 2024-05-11 91/week @ 2024-05-18 80/week @ 2024-05-25 85/week @ 2024-06-01 100/week @ 2024-06-08 130/week @ 2024-06-15 53/week @ 2024-06-22 38/week @ 2024-06-29 30/week @ 2024-07-06 17/week @ 2024-07-13

145 downloads per month

MIT/Apache

6KB

ternary-rs

A Rust library for emulating the ternary operator from C/C++ (among other languages)

Exposes two macros that do the same thing:

  • Choose between two macros ifelse! and ternary
ifelse!(condition, true value, false value)
ternary!(condition, true value, false value)

Usage

Add this to your Cargo.toml:

[dependencies]
ternary-rs = "1.0.0"

Example

let cond = true;
let result = if_else!(cond, 1, 0);
assert_eq!(1, result);
assert_ne!(0, result);

// If you find if_else!() unclear, you can use the ternary!() macro and be explicit instead!
let result = ternary!(cond, 1, 0);
assert_eq!(1, result);
assert_ne!(0, result);

License

ternary-rs is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

No runtime deps