I am trying to build a wrapper struct around the gnuplot lib for Rust.
I want to plot multiple sets of lines in the same 2D-axes object, therefore I need to keep the Axes2D
around.
How can I fix this structure? The figure
and the axes
fields will live exactly as long as the plot
struct itself.
use gnuplot::{Axes2D, Figure, Caption, Color};
pub struct Plot {
figure: Figure,
axes: &mut Axes2D,
}
impl Plot {
pub fn new() -> Plot {
let fig = Figure::new();
Plot {
figure: fig,
axes: fig.axes2d(),
}
}
}
This fails with the following compiler error:
plot.rs:6:11: 6:22 error: missing lifetime specifier [E0106]
plot.rs:6 axes: &mut Axes2D,
I've tried adding lifetime 'a
at the struct, field and impl, but this gives me different errors. Since I'm not sure what I'm doing, I was wondering if someone could explain how to achieve this.