3个版本
0.1.3 | 2021年2月7日 |
---|---|
0.1.2 | 2021年2月7日 |
0.1.1 | 2021年2月7日 |
#1066 in 过程宏
7KB
iffy-rs
Rust过程宏,用于模拟C语言类语言的三目运算符。
此crate定义了一个宏,用于模拟在C、C++、Java等C语言类语言中找到的三目运算符。该宏可以用于使Rust代码中的条件表达式更加紧凑。
例如,以下纯Rust代码
let a = 20;
let b = 30;
// This is the part we will be able to simplify
let min = if a < b {
a
} else {
b
};
// Check the result
assert_eq!(min, a);
... 可以缩短为以下内容,使用此crate
let a = 20;
let b = 30;
// Shortened from the previous example
let min = iffy::i!(a < b ? a : b);
// Check the result
assert_eq!(min, a);
lib.rs
:
此crate定义了一个宏,用于模拟在C、C++、Java等C语言类语言中找到的三目运算符。该宏可以用于使Rust代码中的条件表达式更加紧凑。
例如,以下纯Rust代码
let a = 20;
let b = 30;
// This is the part we will be able to simplify
let min = if a < b {
a
} else {
b
};
// Check the result
assert_eq!(min, a);
... 可以缩短为以下内容,使用此crate
let a = 20;
let b = 30;
// Shortened from the previous example
let min = iffy::i!(a < b ? a : b);
// Check the result
assert_eq!(min, a);
依赖项
~1.5MB
~35K SLoC