Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 'static lifetime requirement for ChartContext #594

Open
DoomDuck opened this issue Jun 4, 2024 · 1 comment
Open

[BUG] 'static lifetime requirement for ChartContext #594

DoomDuck opened this issue Jun 4, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@DoomDuck
Copy link

DoomDuck commented Jun 4, 2024

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

@DoomDuck DoomDuck added the bug Something isn't working label Jun 4, 2024
@kjakx
Copy link

kjakx commented Dec 12, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants