0

I'm trying to use Cairo with Rust and came to a problem where I can't find a good solution for:

let (width, height) = (400., 300.);

let window = gtk::ApplicationWindow::new(application);
window.set_default_size(width as i32, height as i32);

let drawing_area = Box::new(DrawingArea::new)();

drawing_area.connect_draw(|_, cr| {
    cr.scale(width, height);
    ...
    });

I assumed I could use width and height directly inside the closure since those are primitive types that are copied by default. Yet the compiler complains:

   |     drawing_area.connect_draw(|_, cr| {
   |                               ^^^^^^^ may outlive borrowed value `width`

I couldn't find a good solution for this issue in the Rust documentation, what is the best way to use outside variables inside a closure?

I can't change the signature of the closure since connect_draw expects exactly two input parameters.

Natjo
  • 2,005
  • 29
  • 75

0 Answers0