25 stable releases
2.3.1 | Dec 18, 2020 |
---|---|
2.2.0 | Nov 25, 2020 |
1.13.0 | Nov 5, 2020 |
1.11.1 | Jul 11, 2020 |
#2080 in Rust patterns
45KB
640 lines
batch_oper
Rename to libsugar
batch_oper provides some batch operation macro for some operations
See https://docs.rs/batch_oper/
here is just a brief introduction
Usage
- Basic
- batch
||
equivalent tobop!(|| 4; == 2, > 3);
4 == 2 || 4 > 3
- batch
&&
equivalent tobop!(&& 4; == 2, > 3);
4 == 2 && 4 > 3
!
equivalent tobop!(|| a; == 1;!, == 2);
1 == a || a == 2
- batch op
equivalent tobop!(&& 5; > ; 2, 3, 6;!);
5 > 2 && 5 > 3 && 6 > 5
- batch
- Set
equivalent tolet mut a = 1; bop!(= a; + 1, - 2;!, * 3);
let mut a = 1; a = a + 1; a = 2 - a; a = a * 3;
- Let
equivalent tobop! { let a|u8 = 1, mut b = 2 }
let a: u8 = 1; let mut b = 2;
- Let chain
- basic
equivalent tolet a = Some(1); let b = Some(2); let _: i32 = bop!(match && Some(va) = a, Some(vb) = b => { 1 } else { 2 });
let a = Some(1); let b = Some(2); let _: i32 = loop { if let Some(va) = a { if let Some(vb) = b { break { 1 }; } } break { 2 }; };
bool
equivalent tolet _: bool = bop!(bool match && Some(va) = a, Some(vb) = b => { 1 } else { 2 });
let _: bool = loop { if let Some(va) = a { if let Some(vb) = b { { 1 }; break true; } } { 2 }; break false; };
!loop
equivalent tolet _: i32 = bop!(!loop match && Some(va) = a, Some(vb) = b => { 1 } else { 2 });
let _: i32 = if let Some(va) = a { if let Some(vb) = b { { 1 } } else { { 2 } } } else { { 2 } }
!loop bool
equivalent tolet _: bool = bop!(!loop bool match && Some(va) = a, Some(vb) = b => { 1 } else { 2 });
let _: bool = if let Some(va) = a { if let Some(vb) = b { { 1 }; true } else { { 2 }; false } } else { { 2 }; false }
- basic
- In
equivalent tolet r = 0..5; let c = bop!(&1, &2 => in && r);
let r = 0..5; let c = r.contains(&1) && r.contains(&2);
||
equivalent tolet c = bop!(&1, &2 => in || r);
let c = r.contains(&1) || r.contains(&2);
- custom funcion name
equivalent tolet c = bop!(has; &1, &2 => in && r);
let c = r.has(&1) && r.has(&2);
Using
equivalent tolet v = (1, 2); let v2 = (3, 4); using!((a, b) = v, (c, d) = v2; { println!("{} {} {} {}", a, b, c, d) })
let v = (1, 2); let v2 = (3, 4); { let (a, b) = v; let (c, d) = v2; { println!("{} {} {} {}", a, b, c, d) } }
Dependencies
~5MB
~70K SLoC