Things you can’t do in Rust (and what to do instead)
I still couldn&#x27;t get or understand an answer to this question: <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;64705654&#x2F;why-i-get-temporary-value-dropped-while-borrowed-if-i-assign-but-not-when-pas" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;64705654&#x2F;why-i-get-tempo...</a><p>Why I can put a temporary inside a single expression, but if I bind it first just to move it inside I&#x27;m not allowed?<p>This works:<p><pre><code>    use lol_html::{element, HtmlRewriter, Settings};
    
    let mut output = vec![];
    
    {
        let mut rewriter = HtmlRewriter::try_new(
            Settings {
                element_content_handlers: vec![
                    &#x2F;&#x2F; Rewrite insecure hyperlinks
                    element!(&quot;a[href]&quot;, |el| {
                        let href = el
                            .get_attribute(&quot;href&quot;)
                            .unwrap()
                            .replace(&quot;http:&quot;, &quot;https:&quot;);
    
                        el.set_attribute(&quot;href&quot;, &amp;href).unwrap();
    
                        Ok(())
                    })
                ],
                ..Settings::default()
            },
            |c: &amp;[u8]| output.extend_from_slice(c)
        ).unwrap();
    
        rewriter.write(b&quot;&lt;div&gt;&lt;a href=&quot;).unwrap();
        rewriter.write(b&quot;http:&#x2F;&#x2F;example.com&gt;&quot;).unwrap();
        rewriter.write(b&quot;&lt;&#x2F;a&gt;&lt;&#x2F;div&gt;&quot;).unwrap();
        rewriter.end().unwrap();
    }
    
    assert_eq!(
        String::from_utf8(output).unwrap(),
        r#&quot;&lt;div&gt;&lt;a href=&quot;https:&#x2F;&#x2F;example.com&quot;&gt;&lt;&#x2F;a&gt;&lt;&#x2F;div&gt;&quot;#
    );
</code></pre>
With the temporary vec moved outside it errors with &quot;temporary value dropped while borrowed&quot; on the &quot;let handlers&quot; line.<p><pre><code>    use lol_html::{element, HtmlRewriter, Settings};
    
    let mut output = vec![];
    
    {
        let handlers = vec![
                    &#x2F;&#x2F; Rewrite insecure hyperlinks
                    element!(&quot;a[href]&quot;, |el| {
                        let href = el
                            .get_attribute(&quot;href&quot;)
                            .unwrap()
                            .replace(&quot;http:&quot;, &quot;https:&quot;);
    
                        el.set_attribute(&quot;href&quot;, &amp;href).unwrap();
    
                        Ok(())
                    }) &#x2F;&#x2F; this element is deemed temporary
                ];

        let mut rewriter = HtmlRewriter::try_new(
            Settings {
                element_content_handlers: handlers,
                ..Settings::default()
            },
            |c: &amp;[u8]| output.extend_from_slice(c)
        ).unwrap();
    
        rewriter.write(b&quot;&lt;div&gt;&lt;a href=&quot;).unwrap();
        rewriter.write(b&quot;http:&#x2F;&#x2F;example.com&gt;&quot;).unwrap();
        rewriter.write(b&quot;&lt;&#x2F;a&gt;&lt;&#x2F;div&gt;&quot;).unwrap();
        rewriter.end().unwrap();
    }
    
    assert_eq!(
        String::from_utf8(output).unwrap(),
        r#&quot;&lt;div&gt;&lt;a href=&quot;https:&#x2F;&#x2F;example.com&quot;&gt;&lt;&#x2F;a&gt;&lt;&#x2F;div&gt;&quot;#
    );</code></pre>