#macro #batch_oper #using #in #let_chain

no-std batch_oper

batch_oper provides some batch operation macro for some operations

19 stable releases

1.12.1 Sep 15, 2020
1.11.1 Jul 11, 2020
1.9.0 Jun 22, 2020
1.5.1 May 19, 2020
1.2.0 Apr 18, 2020

#57 in Development tools

Download history 46/week @ 2020-06-09 47/week @ 2020-06-16 11/week @ 2020-06-23 22/week @ 2020-06-30 59/week @ 2020-07-07 39/week @ 2020-07-14 35/week @ 2020-07-21 7/week @ 2020-07-28 3/week @ 2020-08-04 36/week @ 2020-08-11 21/week @ 2020-08-18 23/week @ 2020-08-25 21/week @ 2020-09-01 56/week @ 2020-09-08 31/week @ 2020-09-15 6/week @ 2020-09-22

118 downloads per month
Used in parser_fuck

MIT license

53KB
881 lines

batch_oper

Rust
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 ||
      bop!(|| 4; == 2, > 3);
      
      equivalent to
      4 == 2 || 4 > 3
      
    • batch &&
      bop!(&& 4; == 2, > 3);
      
      equivalent to
      4 == 2 && 4 > 3
      
    • !
      bop!(|| a; == 1;!, == 2);
      
      equivalent to
      1 == a || a == 2
      
    • batch op
      bop!(&& 5; > ; 2, 3, 6;!);
      
      equivalent to
      5 > 2 && 5 > 3 && 6 > 5
      
  • Set
    let mut a = 1;
    bop!(= a; + 1, - 2;!, * 3);
    
    equivalent to
    let mut a = 1;
    a = a + 1;
    a = 2 - a;
    a = a * 3;
    
  • Let
    bop! { let a|u8 = 1, mut b = 2 }
    
    equivalent to
    let a: u8 = 1;
    let mut b = 2;
    
  • Let chain
    • basic
      let a = Some(1);
      let b = Some(2);
      
      let _: i32 = bop!(match && Some(va) = a, Some(vb) = b => {
          1
      } else {
          2
      });
      
      equivalent to
      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
      let _: bool = bop!(bool match && Some(va) = a, Some(vb) = b => {
          1
      } else {
          2
      });
      
      equivalent to
      let _: bool = loop {
          if let Some(va) = a {
              if let Some(vb) = b {
                  { 1 };
                  break true;
              }
          }
          { 2 };
          break false;
      };
      
    • !loop
      let _: i32 = bop!(!loop match && Some(va) = a, Some(vb) = b => {
          1
      } else {
          2
      });
      
      equivalent to
      let _: i32 = if let Some(va) = a {
          if let Some(vb) = b {
              { 1 }
          } else { { 2 } }
      } else  { { 2 } }
      
    • !loop bool
      let _: bool = bop!(!loop bool match && Some(va) = a, Some(vb) = b => {
          1
      } else {
          2
      });
      
      equivalent to
      let _: bool = if let Some(va) = a {
          if let Some(vb) = b {
              { 1 }; true
          } else { { 2 }; false }
      } else  { { 2 }; false }
      
  • In
    let r = 0..5;
    let c = bop!(&1, &2 => in && r);
    
    equivalent to
    let r = 0..5;
    let c = r.contains(&1) && r.contains(&2);
    
    • ||
      let c = bop!(&1, &2 => in || r);
      
      equivalent to
      let c = r.contains(&1) || r.contains(&2);
      
    • custom funcion name
      let c = bop!(has; &1, &2 => in && r);
      
      equivalent to
      let c = r.has(&1) && r.has(&2);
      
  • Using
    let v = (1, 2);
    let v2 = (3, 4);
    using!((a, b) = v, (c, d) = v2; {
      println!("{} {} {} {}", a, b, c, d)
    })
    
    equivalent to
    let v = (1, 2);
    let v2 = (3, 4);
    {
      let (a, b) = v;
      let (c, d) = v2;
      {
        println!("{} {} {} {}", a, b, c, d)
      }
    }
    

No runtime deps

Features

  • chain_panic
  • chain_todo
  • combin
  • combin-mutual
  • macro-lit
  • named-into
  • re-exports
  • side-effect
  • std