title: Can a Rust macro set a variable and return a value at the same time?
body: <p>I want to create a macro which will take as parameters <code>($var:ident, $val:expr)</code>. The macro should set the variable <code>$var</code> to the value of <code>$val</code>, clone it, and then return the clone. This is my attempt:</p>
  
  <pre><code>macro_rules! my_macro {
      ($var:ident, $val:expr) =&gt; {{
          let $var = $val;
          $var.clone()
      }}
  }
  
  fn main() {
      println!("{}", my_macro!(x, 5));
      println!("{}", x);
  }
  </code></pre>
  
  <p>It doesn't work because the <code>let</code> statement is inside a block. If I try to solve the problem by changing <code>{{</code> to <code>{</code>, then it produces a syntax error. Is there any way to solve this?</p>