Skip to content

Commit

Permalink
print_job: fix send() closure
Browse files Browse the repository at this point in the history
Pass a result, since error is set only on failure. Also avoid
passing the job itself to the rust closure since that is redundant.
  • Loading branch information
pbor committed Jan 19, 2024
1 parent 0665f3c commit 172aef8
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions gtk4/src/print_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ use std::boxed::Box as Box_;

impl PrintJob {
#[doc(alias = "gtk_print_job_send")]
pub fn send<P: Fn(&PrintJob, &glib::Error) + 'static>(&self, callback: P) {
pub fn send<P: Fn(Result<(), glib::Error>) + 'static>(&self, callback: P) {
let callback_data: Box_<P> = Box_::new(callback);
unsafe extern "C" fn callback_func<P: Fn(&PrintJob, &glib::Error) + 'static>(
print_job: *mut ffi::GtkPrintJob,
_print_job: *mut ffi::GtkPrintJob,
user_data: glib::ffi::gpointer,
error: *const glib::ffi::GError,
) {
let print_job = from_glib_borrow(print_job);
let error = from_glib_borrow(error);
let result = if error.is_null() {
Ok(())
} else {
Err(from_glib_none(error))
};
let callback: &P = &*(user_data as *mut _);
(*callback)(&print_job, &error);
(*callback)(&print_job, result);
}
let callback = Some(callback_func::<P> as _);
unsafe extern "C" fn dnotify_func<P: Fn(&PrintJob, &glib::Error) + 'static>(
unsafe extern "C" fn dnotify_func<P: Fn(Result<(), glib::Error>) + 'static>(
data: glib::ffi::gpointer,
) {

Check failure on line 27 in gtk4/src/print_job.rs

View workflow job for this annotation

GitHub Actions / build

failed to resolve: could not resolve path `print_job`

Check failure on line 27 in gtk4/src/print_job.rs

View workflow job for this annotation

GitHub Actions / build

mismatched types
let _callback: Box_<P> = Box_::from_raw(data as *mut _);
Expand Down

0 comments on commit 172aef8

Please sign in to comment.