From c39a4d5655ad33a02a5539a5e8437cd4913b5f42 Mon Sep 17 00:00:00 2001 From: mo8it Date: Fri, 13 Sep 2024 13:10:59 +0200 Subject: [PATCH] Allow borrowing when using from_explicit_callback --- egui_plot/src/items/values.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/egui_plot/src/items/values.rs b/egui_plot/src/items/values.rs index f9ed3c4..fe2be68 100644 --- a/egui_plot/src/items/values.rs +++ b/egui_plot/src/items/values.rs @@ -156,7 +156,7 @@ impl Default for Orientation { /// These can be an owned `Vec` or generated with a function. pub enum PlotPoints<'a> { Owned(Vec), - Generator(ExplicitGenerator), + Generator(ExplicitGenerator<'a>), Borrowed(&'a [PlotPoint]), } @@ -207,7 +207,7 @@ impl<'a> PlotPoints<'a> { /// Draw a line based on a function `y=f(x)`, a range (which can be infinite) for x and the number of points. pub fn from_explicit_callback( - function: impl Fn(f64) -> f64 + 'static, + function: impl Fn(f64) -> f64 + 'a, x_range: impl RangeBounds, points: usize, ) -> Self { @@ -391,13 +391,13 @@ pub enum PlotGeometry<'a> { // ---------------------------------------------------------------------------- /// Describes a function y = f(x) with an optional range for x and a number of points. -pub struct ExplicitGenerator { - function: Box f64>, +pub struct ExplicitGenerator<'a> { + function: Box f64 + 'a>, x_range: RangeInclusive, points: usize, } -impl ExplicitGenerator { +impl ExplicitGenerator<'_> { fn estimate_bounds(&self) -> PlotBounds { let mut bounds = PlotBounds::NOTHING;