I am writing a gtk based desktop application in rust. There is a type that has such a method:
fn set_draw_func <P: FnMut (& DrawingArea , & Context , i32 , i32 ) + 'static>(
&self,
draw_func: P
)
I call this method with the following sentence: drawing_area.set_draw_func(draw_function);
The function draw_function() is defined as follows: fn draw_function(drawing_area: &DrawingArea, content: &Context, width:i32, height:i32){}
But there is the following error when compiling: Compiling monitor-input-device v0.1.0 (/home/hy/workspace/rust/gtk4/monitor-input-device) error[E0631]: type mismatch in function arguments --> src/event_analyse_window.rs:12:30 | 12 | drawing_area.set_draw_func(&draw_function); | ------------- ^^^^^^^^^^^^^^ expected signature of fn(&DrawingArea, >k4::cairo::Context, i32, i32) -> _
| | | required by a bound introduced by this call ... 19 | fn draw_function<'r, 's>(drawing_area: &'r DrawingArea, content: &'s Context, width: i32, height: i32) -> () {} | ------------------------------------------------------------------------------------------------------------ found signature of for<'r, 's> fn(&'r DrawingArea, &'s cairo::Context, i32, i32) -> _
| = note: required because of the requirements on the impl of for<'r, 's> FnMut<(&'r DrawingArea, &'s gtk4::cairo::Context, i32, i32)>
for &for<'r, 's> fn(&'r DrawingArea, &'s cairo::Context, i32, i32) {draw_function}
note: required by a bound in set_draw_func
--> /home/hy/.cargo/git/checkouts/gtk4-rs-e74ad56283dfeb5e/86c1548/gtk4/src/drawing_area.rs:17:25 | 17 | fn set_draw_func<P: FnMut(&DrawingArea, &cairo::Context, i32, i32) + 'static>( | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in set_draw_func
For more information about this error, try rustc --explain E0631
. error: could not compile monitor-input-device
due to previous error