2 releases

0.1.1 Mar 9, 2024
0.1.0 Mar 9, 2024

#150 in Procedural macros

Download history 310/week @ 2024-03-09 11/week @ 2024-03-16 1/week @ 2024-03-23 30/week @ 2024-03-30 8/week @ 2024-04-06

59 downloads per month

Apache-2.0

11KB
109 lines

macrors

A simple custom macro library in Rust.

APIs Documents

1.Usage

Add this to your Cargo.toml:

[dependencies]
macrors = "0.1"

2.APIs

2.1.Operator

2.1.1.ternary

let seed = 10;

let pos = ternary!(seed % 2 == 0, 1, -1);
let neg = ternary!((seed - 1) % 2 == 0, 1, -1);
assert_eq!(1, pos);
assert_eq!(-1, neg);
// bool
let seed = 10;

let is_even = ternary!(seed % 2 == 0, true, false);
assert!(is_even);
// &str
let seed = 10;

let result = ternary!(seed > 5, "greater than 5", "less than or equal to 5");
assert_eq!("greater than 5", result);

2.1.2.ternary_eq

let eq = ternary_eq!(2, 2, 1, -1);
let ne = ternary_eq!(1, 2, 1, -1);

assert_eq!(1, eq);
assert_eq!(-1, ne);
// date-time
let now = SystemTime::now();
let now_add = now.add(Duration::from_millis(1_000));
let now_sub = now.sub(Duration::from_millis(1_000));

let eq = ternary_eq!(now, now, 1, -1);
let ne = ternary_eq!(now, now.add(Duration::from_millis(1_000)), now_add, now_sub);

assert_eq!(1, eq);
assert_eq!(now_sub, ne);

2.1.3.ternary_ne

let ne = ternary_ne!(3, 2, 1, -1);
let eq = ternary_ne!(2, 2, 1, -1);

assert_eq!(1, ne);
assert_eq!(-1, eq);
// date-time
let now = SystemTime::now();
let now_add = now.add(Duration::from_millis(1_000));
let now_sub = now.sub(Duration::from_millis(1_000));

let ne = ternary_ne!(now, now.add(Duration::from_millis(1_000)), 1, -1);
let eq = ternary_ne!(now, now, now_add,now_sub);

assert_eq!(1, ne);
assert_eq!(now_sub, eq);

No runtime deps