error[E0716]: temporary value dropped while borrowed
--> src/emitter/mod.rs:59:28
|
27 | impl<'a, T: Debug> Emitter<'a, T> {
| -- lifetime `'a` defined here
...
59 | let events = &mut *self.events.lock().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
...
69 | *last_event = Some((&e[last_index]).clone());
| ------------------------ argument requires that borrow lasts for `'a`
70 | }
71 | }
| - temporary value is freed at the end of this statement
For more information about this error, try `rustc --explain E0716`.
error: could not compile `elib` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed
No it won't be. Arc is reference-counted. So if you call Arc::clone(event) (where event is of type Arc<Mutex<Option<Events<T>>>>), then the struct is not copied. Only the reference count is increased.
You can read the docs here.
Thank you!
but notice that Events is Vec<Event> (type Events<T> = Vec<Event<T>>) and last_count should be a refrence to one event not a vector of events.
idx will be the index of the event you want to store.
If you just have one large vector of events, then you can take this one step further - just store the indices, and when calling the function, pass the correct reference.