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

Relax too strict life times on ChartBuilder #610

Merged
merged 2 commits into from
Sep 8, 2024

Conversation

jchacks
Copy link
Contributor

@jchacks jchacks commented Jul 7, 2024

The ChartBuilder's lifetimes meant that the root_area was not allowed to be dropped after the builder has been finalised (i.e. with a call to build_cartesian_2d). I'm not 100% sure but this feels like unintended behaviour.

Since the root_area is cloned and no references to the original (usually root DrawingArea) are maintained by the resulting ChartContext this lifetime can be relaxed.

This should allow for ChartContexts to outlive the root drawing areas.

let drawing_area = create_mocked_drawing_area(640, 480, |_| {});
let mut chart = ChartBuilder::on(&drawing_area)
    .build_cartesian_2d(0f32..10f32, (1e-6f32..1f32).log_scale())
    .unwrap();
drop(drawing_area); // This drop would not be allowed before
// do something with `chart` 

Copy link
Member

@AaronErhardt AaronErhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@AaronErhardt AaronErhardt merged commit 0321e80 into plotters-rs:master Sep 8, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants