emilk / egui_plot

2D plotting library in Rust for egui

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Non-static Plot::label_formatter closure

zdimension opened this issue · comments

Is your feature request related to a problem? Please describe.

I'm using the Plot component for physical measurements, for which I want to calculate the instantaneous derivative and definite integral, both of which should be displayed in the mouse-hover label.

Problem: the closure expected by Plot::label_formatter needs to be static. I want to compute derivatives and integrals in the label (values that require accessing other plot points than the one being hovered), but this requires borrowing things in the closure, but since it needs to be static, I can't borrow non-static data. I have to resort to weird hacks such as unsafe &* lifetime extension. There may be other ways around, with Arc maybe, but they're not ergonomic.

Describe the solution you'd like

Allow Plot::label_formatter to take a non-static closure.