title: Rust lifetimes : Static reference lives to short to be fed into a function?
body: <p>I'm discovering rust and have a hard time with lifetimes.</p>
  
  <p>For example, I am experimenting with GUIs a little :</p>
  
  <pre><code>#[macro_use]extern crate native_windows_gui as nwg;
  
  use nwg::{Ui, Event, EventArgs};
  
  nwg_template!(
      head: setup_ui&lt;&amp;'static str&gt;,
      controls: [
          ("MainWindow", nwg_window!(title="Test1"; size=(180,50))),
          ("SetButton", nwg_button!(parent="MainWindow"; visible=false)),
          ("BackButton", nwg_button!(parent="MainWindow"; text="&lt;"; position=(10,10); size=(30,30))),
          ("Text", nwg_textbox!(parent="MainWindow"; readonly=true; position=(40,10); size=(100,30))),
          ("NextButton", nwg_button!(parent="MainWindow"; text="&gt;"; position=(140,10); size=(30,30)))
      ];
      events: [
          ("SetButton", "Set", Event::Click, |app,_,_,_| {
              let display = nwg_get_mut!(app; ("Text", nwg::TextBox));
              let index = nwg_get!(app; ("Index", &amp;str));
              display.set_text(**index);
          }),
          ("BackButton", "Back", Event::Click, |_,_,_,_| {}),
          ("NextButton", "Next", Event::Click, |_,_,_,_| {})
      ];
      resources: [];
      values: [
          ("Index", "Test")
      ]
  );
  
  fn create_ui(data: &amp;'static str) -&gt; Result&lt;Ui&lt;&amp;'static str&gt;, nwg::Error&gt; {
     let app: Ui&lt;&amp;'static str&gt;;
  
      match Ui::new() {
          Ok(ui) =&gt; { app = ui; },
          Err(e) =&gt; { return Err(e) }
      }
  
      if let Err(e) = setup_ui(&amp;app) {
          return Err(e);
      }
  
      app.pack_value(&amp;"Data", &amp;data);
      app.trigger(&amp;"SetButton", Event::Click, EventArgs::None);
  
      if let Err(e) =app.commit() {
          Err(e)
      } else {
          Ok(app)
      }
  }
  
  fn main() {
      let data = "Foo";
      let _ui = create_ui(data).expect("Oups");
      nwg::dispatch_events();
  }
  </code></pre>
  
  <p>I don't understand why in the function <code>create_ui</code>, <code>data</code> doesn't live long enough to be fed in <code>app.pack_value()</code>.</p>
  
  <p>It seems to me that the <code>'static</code> lifetime would make it survive long enough.</p>
  
  <p>But the compiler insits it dies at the end of <code>create_ui</code> and therefore cannot be used as <code>app.pack_value("Data", &amp;data);</code></p>
  
  <p>What am I doing wrong ?</p>