Specify lifetime of a returned reference to a closure
<p>Given this struct: </p>

<pre><code>struct Token&lt;'a&gt; {
     r: &amp;'a Regex,
     f: &amp;'a Fn(String) -&gt; Symbol
}
</code></pre>

<p>I can't figure out the right syntax to specify the closure lifetime when returning it from a fn: </p>

<pre><code>fn get_tokens&lt;'a&gt;() -&gt; Vec&lt;Token&lt;'a&gt;&gt; {
    static ref NUMBER: Regex = Regex::new(r"$(\d+|\d*\.\d+)").unwrap(); // TODO avoid "000"?
    let num_token = Token{ r: &amp;*NUMBER, f: &amp;|s| Symbol::Number(s) };
    let tokens = vec![num_token];

    tokens
}
</code></pre>

<p>Without a lifetime parameter, I get the error that the borrowed value doesn't life long enough: </p>

<pre class="lang-none prettyprint-override"><code>error: borrowed value does not live long enough
   --&gt; src\syntax\lex.rs:49:45
   |
49 |     let num_token = Token{ r: &amp;*NUMBER, f: &amp;|s| Symbol::Number(s) };
   |                                             ^^^^^^^^^^^^^^^^^^^^^ temporary value created here
...
53 | }
   | - temporary value only lives until here
   |
note: borrowed value must be valid for the lifetime 'a as defined on the block at 36:38...
     --&gt; src\syntax\lex.rs:36:39
   |
36 | fn get_tokens&lt;'a&gt;() -&gt; Vec&lt;Token&lt;'a&gt;&gt; {
   |                                       ^
</code></pre>

<p>And I can't find any examples that show specifying a lifetime parameter for a closure like this. </p>