I am currently learning Rust and I am struggling with lifetimes while creating a simple observer that would store a callback of an arbitrary type.
I started with a basic struct
struct Signal<T> {
slots: Vec<|T|>
}
which got me the initial lifetime error
signal_test.rs:7:16: 7:19 error: explicit lifetime bound required
signal_test.rs:7 slots: Vec<|T|>
^~~
error: aborting due to previous error
So next I try adding some lifetime specifiers.
struct Signal<'r, T> {
slots: Vec<'r |T|>
}
which gets me some new errors
signal_test.rs:7:12: 7:23 error: wrong number of lifetime parameters: expected 0, found 1 [E0107]
signal_test.rs:7 slots: Vec<'r |T|>
^~~~~~~~~~~
signal_test.rs:7:19: 7:22 error: explicit lifetime bound required
signal_test.rs:7 slots: Vec<'r |T|>
I have not been able to find enough rust lifetime documentation to hint at what I need to do to fix this. It could just be this is not a good pattern to use in Rust. Some help and comments would be appreciated.
Try using this:
struct Signal<'r, T> {
slots: Vec<|T|: 'r>
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With