plotters
plotters copied to clipboard
[BUG] 'static lifetime requirement for `ChartContext`
Describe the bug I wanted to increase the size of the labels but got a lifetime error. I haven't found a workaround, nor the cause of the error.
However, this looks similar to #62
To Reproduce
use plotters::{backend::SVGBackend, prelude::*};
fn main() {
let root = SVGBackend::new("plot.svg", (1920, 1080)).into_drawing_area();
let mut chart = ChartBuilder::on(&root)
.build_cartesian_2d(0..1, 0..1)
.unwrap();
// Using `label_style` results in chart being borrowed for 'static
chart.configure_mesh().label_style(24);
}
Compiler output
error[E0597]: `chart` does not live long enough
--> src/main.rs:11:5
|
6 | let mut chart = ChartBuilder::on(&root)
| --------- binding `chart` declared here
...
11 | chart.configure_mesh().label_style(24);
| ^^^^^-----------------
| |
| borrowed value does not live long enough
| argument requires that `chart` is borrowed for `'static`
12 | }
| - `chart` dropped here while still borrowed
Version Information
The behavior is present on 0.3.6 which is the current state of master
Rust version: 1.78.0
In the following part of the code, changing the 'static lifetime parameters to 'a appears to solve the problem.
https://github.com/plotters-rs/plotters/blob/3ad52da872c652647b5add208b46e8ba850608de/plotters/src/style/text.rs#L223C1-L227C2