I want to write a 'static CAN-"Driver", where T: Handler can register themselves to receive a filtered version of all CAN-Messages, as long as the Drivers aren't dropped.
The only solution I can come up with is a double linked list of trait items that implement Handler, but it requires much unsafe code.
Can you be more specific about where the lifetimes come from?
If something lives forever, then it can't hold on to a reference borrowed for a temporary lifetime 'a. It would become a dangling pointer.
However, there's no problem giving the handlers a temporary permission to access an object, and that's the default when you call functions, e.g. handle(&self, data: &CanData) could be called with lifetimes like handle<'a>(&'static self, data: &'a CanData).
If your handler needs to keep some data in self, then it either has to exclusively own that data, or has to use Arc (or equivalent) if the data may be accessed from outside of the handler too.
I've isolated the described structure in a new repository.
Currently it is using the double linked list unsafe implementation.
As I do not have a HEAP, everything needs to be located in the DATA-Segment (the CAN-Driver) or on the Stack (the Handlers(named "Receivers" in the demo repo)).
The Driver exists for the entire runtime of the program. The Handlers are part of a Future that will get dropped eventually.
In a previous implementation, I used an array of Queues in the CanDriver struct. Handlers get a reference to a free queue. This method has a few disadvantages: