Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Use Into<Option<_>> in argument position where applicable #1590

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions gdk-pixbuf/src/auto/pixbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Pixbuf {

//#[doc(alias = "gdk_pixbuf_new_from_data")]
//#[doc(alias = "new_from_data")]
//pub fn from_data(data: &[u8], colorspace: Colorspace, has_alpha: bool, bits_per_sample: i32, width: i32, height: i32, rowstride: i32, destroy_fn: Option<Box_<dyn FnOnce(&Vec<u8>) + 'static>>) -> Pixbuf {
//pub fn from_data(data: &[u8], colorspace: Colorspace, has_alpha: bool, bits_per_sample: i32, width: i32, height: i32, rowstride: i32, destroy_fn: Option<Box_<dyn FnOnce(&[u8]) + 'static>>) -> Pixbuf {
// unsafe { TODO: call ffi:gdk_pixbuf_new_from_data() }
//}

Expand Down Expand Up @@ -167,15 +167,20 @@ impl Pixbuf {

#[doc(alias = "gdk_pixbuf_new_from_stream")]
#[doc(alias = "new_from_stream")]
pub fn from_stream(
pub fn from_stream<'a, P: IsA<gio::Cancellable>>(
stream: &impl IsA<gio::InputStream>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
cancellable: impl Into<Option<&'a P>>,
) -> Result<Pixbuf, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::gdk_pixbuf_new_from_stream(
stream.as_ref().to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
cancellable
.into()
.as_ref()
.map(|p| p.as_ref())
.to_glib_none()
.0,
&mut error,
);
if error.is_null() {
Expand All @@ -188,12 +193,12 @@ impl Pixbuf {

#[doc(alias = "gdk_pixbuf_new_from_stream_at_scale")]
#[doc(alias = "new_from_stream_at_scale")]
pub fn from_stream_at_scale(
pub fn from_stream_at_scale<'a, P: IsA<gio::Cancellable>>(
stream: &impl IsA<gio::InputStream>,
width: i32,
height: i32,
preserve_aspect_ratio: bool,
cancellable: Option<&impl IsA<gio::Cancellable>>,
cancellable: impl Into<Option<&'a P>>,
) -> Result<Pixbuf, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
Expand All @@ -202,7 +207,12 @@ impl Pixbuf {
width,
height,
preserve_aspect_ratio.into_glib(),
cancellable.map(|p| p.as_ref()).to_glib_none().0,
cancellable
.into()
.as_ref()
.map(|p| p.as_ref())
.to_glib_none()
.0,
&mut error,
);
if error.is_null() {
Expand Down Expand Up @@ -465,7 +475,7 @@ impl Pixbuf {

//#[doc(alias = "gdk_pixbuf_get_options")]
//#[doc(alias = "get_options")]
//pub fn options(&self) -> /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 } {
//pub fn options(&self) -> /*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 } {
// unsafe { TODO: call ffi:gdk_pixbuf_get_options() }
//}

Expand Down Expand Up @@ -534,37 +544,37 @@ impl Pixbuf {
}

//#[doc(alias = "gdk_pixbuf_save")]
//pub fn save(&self, filename: impl AsRef<std::path::Path>, type_: &str, error: Option<&mut glib::Error>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> bool {
//pub fn save<'a>(&self, filename: impl AsRef<std::path::Path>, type_: &str, error: impl Into<Option<&'a mut glib::Error>>, : /*Unimplemented*/Basic: VarArgs) -> bool {
// unsafe { TODO: call ffi:gdk_pixbuf_save() }
//}

//#[doc(alias = "gdk_pixbuf_save_to_buffer")]
//pub fn save_to_buffer(&self, type_: &str, error: Option<&mut glib::Error>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> Option<Vec<u8>> {
//pub fn save_to_buffer<'a>(&self, type_: &str, error: impl Into<Option<&'a mut glib::Error>>, : /*Unimplemented*/Basic: VarArgs) -> Option<Vec<u8>> {
// unsafe { TODO: call ffi:gdk_pixbuf_save_to_buffer() }
//}

//#[doc(alias = "gdk_pixbuf_save_to_callback")]
//pub fn save_to_callback<P: FnMut(&Vec<u8>, usize, &glib::Error) -> bool>(&self, save_func: P, type_: &str, error: Option<&mut glib::Error>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> bool {
//pub fn save_to_callback<'a, P: FnMut(&[u8], usize, &glib::Error) -> bool>(&self, save_func: P, type_: &str, error: impl Into<Option<&'a mut glib::Error>>, : /*Unimplemented*/Basic: VarArgs) -> bool {
// unsafe { TODO: call ffi:gdk_pixbuf_save_to_callback() }
//}

//#[doc(alias = "gdk_pixbuf_save_to_callbackv")]
//pub fn save_to_callbackv<P: FnMut(&Vec<u8>, usize, &glib::Error) -> bool>(&self, save_func: P, type_: &str, option_keys: &[&str], option_values: &[&str]) -> Result<(), glib::Error> {
//pub fn save_to_callbackv<P: FnMut(&[u8], usize, &glib::Error) -> bool>(&self, save_func: P, type_: &str, option_keys: &[&str], option_values: &[&str]) -> Result<(), glib::Error> {
// unsafe { TODO: call ffi:gdk_pixbuf_save_to_callbackv() }
//}

//#[doc(alias = "gdk_pixbuf_save_to_stream")]
//pub fn save_to_stream(&self, stream: &impl IsA<gio::OutputStream>, type_: &str, cancellable: Option<&impl IsA<gio::Cancellable>>, error: Option<&mut glib::Error>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> bool {
//pub fn save_to_stream<'a, P: IsA<gio::Cancellable>>(&self, stream: &impl IsA<gio::OutputStream>, type_: &str, cancellable: impl Into<Option<&'a P>>, error: impl Into<Option<&'a mut glib::Error>>, : /*Unimplemented*/Basic: VarArgs) -> bool {
// unsafe { TODO: call ffi:gdk_pixbuf_save_to_stream() }
//}

//#[doc(alias = "gdk_pixbuf_save_to_stream_async")]
//pub fn save_to_stream_async<P: FnOnce(Result<(), glib::Error>) + 'static>(&self, stream: &impl IsA<gio::OutputStream>, type_: &str, cancellable: Option<&impl IsA<gio::Cancellable>>, callback: P, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
//pub fn save_to_stream_async<'a, P: IsA<gio::Cancellable>, Q: FnOnce(Result<(), glib::Error>) + 'static>(&self, stream: &impl IsA<gio::OutputStream>, type_: &str, cancellable: impl Into<Option<&'a P>>, callback: Q, : /*Unimplemented*/Basic: VarArgs) {
// unsafe { TODO: call ffi:gdk_pixbuf_save_to_stream_async() }
//}

//
//pub fn save_to_stream_future(&self, stream: &(impl IsA<gio::OutputStream> + Clone + 'static), type_: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
//pub fn save_to_stream_future(&self, stream: &(impl IsA<gio::OutputStream> + Clone + 'static), type_: &str, : /*Unimplemented*/Basic: VarArgs) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {

//let stream = stream.clone();
//let type_ = String::from(type_);
Expand Down
38 changes: 26 additions & 12 deletions gdk-pixbuf/src/auto/pixbuf_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,20 @@ impl PixbufAnimation {

#[doc(alias = "gdk_pixbuf_animation_new_from_stream")]
#[doc(alias = "new_from_stream")]
pub fn from_stream(
pub fn from_stream<'a, P: IsA<gio::Cancellable>>(
stream: &impl IsA<gio::InputStream>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
cancellable: impl Into<Option<&'a P>>,
) -> Result<PixbufAnimation, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::gdk_pixbuf_animation_new_from_stream(
stream.as_ref().to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
cancellable
.into()
.as_ref()
.map(|p| p.as_ref())
.to_glib_none()
.0,
&mut error,
);
if error.is_null() {
Expand All @@ -77,10 +82,14 @@ impl PixbufAnimation {

#[doc(alias = "gdk_pixbuf_animation_new_from_stream_async")]
#[doc(alias = "new_from_stream_async")]
pub fn from_stream_async<P: FnOnce(Result<PixbufAnimation, glib::Error>) + 'static>(
pub fn from_stream_async<
'a,
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<PixbufAnimation, glib::Error>) + 'static,
>(
stream: &impl IsA<gio::InputStream>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: P,
cancellable: impl Into<Option<&'a P>>,
callback: Q,
) {
let main_context = glib::MainContext::ref_thread_default();
let is_main_context_owner = main_context.is_owner();
Expand All @@ -92,10 +101,10 @@ impl PixbufAnimation {
"Async operations only allowed if the thread is owning the MainContext"
);

let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
let user_data: Box_<glib::thread_guard::ThreadGuard<Q>> =
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
unsafe extern "C" fn from_stream_async_trampoline<
P: FnOnce(Result<PixbufAnimation, glib::Error>) + 'static,
Q: FnOnce(Result<PixbufAnimation, glib::Error>) + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut gio::ffi::GAsyncResult,
Expand All @@ -108,16 +117,21 @@ impl PixbufAnimation {
} else {
Err(from_glib_full(error))
};
let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
let callback: Box_<glib::thread_guard::ThreadGuard<Q>> =
Box_::from_raw(user_data as *mut _);
let callback: P = callback.into_inner();
let callback: Q = callback.into_inner();
callback(result);
}
let callback = from_stream_async_trampoline::<P>;
let callback = from_stream_async_trampoline::<Q>;
unsafe {
ffi::gdk_pixbuf_animation_new_from_stream_async(
stream.as_ref().to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
cancellable
.into()
.as_ref()
.map(|p| p.as_ref())
.to_glib_none()
.0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
Expand Down
2 changes: 1 addition & 1 deletion gdk-pixbuf/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 1b34ebba86cb)
Generated by gir (https://github.com/gtk-rs/gir @ 24f0d6639caa)
from gir-files (https://github.com/gtk-rs/gir-files @ dfdf5ed146d5)
2 changes: 1 addition & 1 deletion gdk-pixbuf/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 1b34ebba86cb)
Generated by gir (https://github.com/gtk-rs/gir @ 24f0d6639caa)
from gir-files (https://github.com/gtk-rs/gir-files @ dfdf5ed146d5)
13 changes: 8 additions & 5 deletions gio/src/auto/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,27 @@ impl Action {
}

#[doc(alias = "g_action_print_detailed_name")]
pub fn print_detailed_name(
pub fn print_detailed_name<'a>(
action_name: &str,
target_value: Option<&glib::Variant>,
target_value: impl Into<Option<&'a glib::Variant>>,
) -> glib::GString {
unsafe {
from_glib_full(ffi::g_action_print_detailed_name(
action_name.to_glib_none().0,
target_value.to_glib_none().0,
target_value.into().to_glib_none().0,
))
}
}
}

pub trait ActionExt: IsA<Action> + 'static {
#[doc(alias = "g_action_activate")]
fn activate(&self, parameter: Option<&glib::Variant>) {
fn activate<'a>(&self, parameter: impl Into<Option<&'a glib::Variant>>) {
unsafe {
ffi::g_action_activate(self.as_ref().to_glib_none().0, parameter.to_glib_none().0);
ffi::g_action_activate(
self.as_ref().to_glib_none().0,
parameter.into().to_glib_none().0,
);
}
}

Expand Down
8 changes: 6 additions & 2 deletions gio/src/auto/action_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ pub trait ActionGroupExt: IsA<ActionGroup> + 'static {
}

#[doc(alias = "g_action_group_activate_action")]
fn activate_action(&self, action_name: &str, parameter: Option<&glib::Variant>) {
fn activate_action<'a>(
&self,
action_name: &str,
parameter: impl Into<Option<&'a glib::Variant>>,
) {
unsafe {
ffi::g_action_group_activate_action(
self.as_ref().to_glib_none().0,
action_name.to_glib_none().0,
parameter.to_glib_none().0,
parameter.into().to_glib_none().0,
);
}
}
Expand Down
Loading
Loading