I have a struct like this:
pub struct GpuApp<'r> {
inst: Nvml,
device: nvml_wrapper::Device<'r>
}
```and am trying to create an instance of this struct.
I currently have:
```rs
let inst = Nvml::init()?;
let dev = inst.device_by_index(0)?;
Ok(Self {
rt,
inst,
device: dev,
})
```However this fails to compile:
```rs
error[E0597]: `inst` does not live long enough
--> src/app.rs:26:19
|
12 | impl<'r> GpuApp<'r> {
| -- lifetime `'r` defined here
...
25 | let inst = Nvml::init()?;
| ---- binding `inst` declared here
26 | let dev = inst.device_by_index(0)?;
| ^^^^ borrowed value does not live long enough
...
31 | device: dev,
| --- this usage requires that `inst` is borrowed for `'r`
32 | })
33 | }
| - `inst` dropped here while still borrowed
error[E0505]: cannot move out of `inst` because it is borrowed
--> src/app.rs:30:13
|
12 | impl<'r> GpuApp<'r> {
| -- lifetime `'r` defined here
...
25 | let inst = Nvml::init()?;
| ---- binding `inst` declared here
26 | let dev = inst.device_by_index(0)?;
| ---- borrow of `inst` occurs here
...
30 | inst,
| ^^^^ move out of `inst` occurs here
31 | device: dev,
| --- this usage requires that `inst` is borrowed for `'r`
```I'm confused as to why this happens, since the Nvml struct should live as long as my struct, so I don't get why it says it is dropped while still borrowed.