Skip to content

Commit

Permalink
make use of impl T wherever possible
Browse files Browse the repository at this point in the history
Except in ClosureExpression because we can't mix both impl & generic types due to
rust-lang/rust#83701
  • Loading branch information
bilelmoussaoui committed Jan 19, 2022
1 parent 7da69d5 commit 2a74d32
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 175 deletions.
32 changes: 10 additions & 22 deletions gdk4/src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ use std::ptr;

impl Clipboard {
#[doc(alias = "gdk_clipboard_read_async")]
pub fn read_async<
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<(gio::InputStream, GString), glib::Error>) + 'static,
>(
pub fn read_async<Q: FnOnce(Result<(gio::InputStream, GString), glib::Error>) + 'static>(
&self,
mime_types: &[&str],
io_priority: glib::Priority,
cancellable: Option<&P>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
Expand Down Expand Up @@ -89,10 +86,10 @@ impl Clipboard {
}

#[doc(alias = "gdk_clipboard_store_async")]
pub fn store_async<P: IsA<gio::Cancellable>, Q: FnOnce(Result<(), glib::Error>) + 'static>(
pub fn store_async<Q: FnOnce(Result<(), glib::Error>) + 'static>(
&self,
io_priority: glib::Priority,
cancellable: Option<&P>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
Expand Down Expand Up @@ -137,14 +134,11 @@ impl Clipboard {
}

#[doc(alias = "gdk_clipboard_read_value_async")]
pub fn read_value_async<
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<glib::Value, glib::Error>) + 'static,
>(
pub fn read_value_async<Q: FnOnce(Result<glib::Value, glib::Error>) + 'static>(
&self,
type_: glib::types::Type,
io_priority: glib::Priority,
cancellable: Option<&P>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
Expand Down Expand Up @@ -193,12 +187,9 @@ impl Clipboard {
}

#[doc(alias = "gdk_clipboard_read_text_async")]
pub fn read_text_async<
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<Option<glib::GString>, glib::Error>) + 'static,
>(
pub fn read_text_async<Q: FnOnce(Result<Option<glib::GString>, glib::Error>) + 'static>(
&self,
cancellable: Option<&P>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
Expand Down Expand Up @@ -244,12 +235,9 @@ impl Clipboard {
}

#[doc(alias = "gdk_clipboard_read_texture_async")]
pub fn read_texture_async<
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<Option<Texture>, glib::Error>) + 'static,
>(
pub fn read_texture_async<Q: FnOnce(Result<Option<Texture>, glib::Error>) + 'static>(
&self,
cancellable: Option<&P>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
Expand Down
14 changes: 4 additions & 10 deletions gdk4/src/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ use std::ptr;

impl Drop {
#[doc(alias = "gdk_drop_read_async")]
pub fn read_async<
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<(gio::InputStream, GString), glib::Error>) + 'static,
>(
pub fn read_async<Q: FnOnce(Result<(gio::InputStream, GString), glib::Error>) + 'static>(
&self,
mime_types: &[&str],
io_priority: glib::Priority,
cancellable: Option<&P>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
Expand Down Expand Up @@ -81,14 +78,11 @@ impl Drop {
}

#[doc(alias = "gdk_drop_read_value_async")]
pub fn read_value_async<
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<glib::Value, glib::Error>) + 'static,
>(
pub fn read_value_async<Q: FnOnce(Result<glib::Value, glib::Error>) + 'static>(
&self,
type_: glib::types::Type,
io_priority: glib::Priority,
cancellable: Option<&P>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
Expand Down
6 changes: 3 additions & 3 deletions gdk4/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Event {

#[doc(alias = "gdk_events_get_angle")]
#[doc(alias = "get_angle")]
pub fn angle<P: AsRef<Event>>(&self, event: P) -> Option<f64> {
pub fn angle(&self, event: impl AsRef<Event>) -> Option<f64> {
skip_assert_initialized!();
unsafe {
let mut angle = mem::MaybeUninit::uninit();
Expand All @@ -49,7 +49,7 @@ impl Event {

#[doc(alias = "gdk_events_get_center")]
#[doc(alias = "get_center")]
pub fn center<P: AsRef<Event>>(&self, event: P) -> Option<(f64, f64)> {
pub fn center(&self, event: impl AsRef<Event>) -> Option<(f64, f64)> {
skip_assert_initialized!();
unsafe {
let mut x = mem::MaybeUninit::uninit();
Expand All @@ -72,7 +72,7 @@ impl Event {

#[doc(alias = "gdk_events_get_distance")]
#[doc(alias = "get_distance")]
pub fn distance<P: AsRef<Event>>(&self, event: P) -> Option<f64> {
pub fn distance(&self, event: impl AsRef<Event>) -> Option<f64> {
skip_assert_initialized!();
unsafe {
let mut distance = mem::MaybeUninit::uninit();
Expand Down
28 changes: 10 additions & 18 deletions gdk4/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,12 @@ pub fn pango_layout_get_clip_region(
}

#[doc(alias = "gdk_content_deserialize_async")]
pub fn content_deserialize_async<
P: IsA<gio::InputStream>,
Q: IsA<gio::Cancellable>,
R: FnOnce(Result<glib::Value, glib::Error>) + Send + 'static,
>(
stream: &P,
pub fn content_deserialize_async<R: FnOnce(Result<glib::Value, glib::Error>) + Send + 'static>(
stream: &impl IsA<gio::InputStream>,
mime_type: &str,
type_: glib::types::Type,
io_priority: glib::Priority,
cancellable: Option<&Q>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: R,
) {
assert_initialized_main_thread!();
Expand Down Expand Up @@ -78,8 +74,8 @@ pub fn content_deserialize_async<
}
}

pub fn content_deserialize_future<P: IsA<gio::InputStream> + Clone + 'static>(
stream: &P,
pub fn content_deserialize_future(
stream: &(impl IsA<gio::InputStream> + Clone + 'static),
mime_type: &str,
type_: glib::types::Type,
io_priority: glib::Priority,
Expand Down Expand Up @@ -222,16 +218,12 @@ pub fn content_register_serializer<
}

#[doc(alias = "gdk_content_serialize_async")]
pub fn content_serialize_async<
P: IsA<gio::OutputStream>,
Q: IsA<gio::Cancellable>,
R: FnOnce(Result<(), glib::Error>) + Send + 'static,
>(
stream: &P,
pub fn content_serialize_async<R: FnOnce(Result<(), glib::Error>) + Send + 'static>(
stream: &impl IsA<gio::OutputStream>,
mime_type: &str,
value: &glib::Value,
io_priority: glib::Priority,
cancellable: Option<&Q>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: R,
) {
assert_initialized_main_thread!();
Expand Down Expand Up @@ -267,8 +259,8 @@ pub fn content_serialize_async<
}
}

pub fn content_serialize_future<P: IsA<gio::OutputStream> + Clone + 'static>(
stream: &P,
pub fn content_serialize_future(
stream: &(impl IsA<gio::OutputStream> + Clone + 'static),
mime_type: &str,
value: &glib::Value,
io_priority: glib::Priority,
Expand Down
4 changes: 2 additions & 2 deletions gtk4/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::Path;
impl Builder {
#[doc(alias = "gtk_builder_new_from_file")]
#[doc(alias = "new_from_file")]
pub fn from_file<T: AsRef<Path>>(file_path: T) -> Self {
pub fn from_file(file_path: impl AsRef<Path>) -> Self {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::gtk_builder_new_from_file(
Expand Down Expand Up @@ -45,7 +45,7 @@ impl Builder {
}

#[doc(alias = "gtk_builder_add_from_file")]
pub fn add_from_file<T: AsRef<Path>>(&self, file_path: T) -> Result<(), glib::Error> {
pub fn add_from_file(&self, file_path: impl AsRef<Path>) -> Result<(), glib::Error> {
unsafe {
let mut error = ::std::ptr::null_mut();
ffi::gtk_builder_add_from_file(
Expand Down
62 changes: 27 additions & 35 deletions gtk4/src/cell_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,43 @@ pub trait CellAreaExtManual {
);

#[doc(alias = "gtk_cell_area_activate_cell")]
fn activate_cell<P: IsA<Widget>, Q: IsA<CellRenderer>, R: AsRef<Event>>(
fn activate_cell(
&self,
widget: &P,
renderer: &Q,
event: &R,
widget: &impl IsA<Widget>,
renderer: &impl IsA<CellRenderer>,
event: &impl AsRef<Event>,
cell_area: &gdk::Rectangle,
flags: CellRendererState,
) -> bool;

#[doc(alias = "gtk_cell_area_event")]
fn event<P: IsA<CellAreaContext>, Q: IsA<Widget>, R: AsRef<Event>>(
fn event(
&self,
context: &P,
widget: &Q,
event: &R,
context: &impl IsA<CellAreaContext>,
widget: &impl IsA<Widget>,
event: &impl AsRef<Event>,
cell_area: &gdk::Rectangle,
flags: CellRendererState,
) -> i32;

#[doc(alias = "gtk_cell_area_cell_get_valist")]
#[doc(alias = "gtk_cell_area_cell_get_property")]
fn cell_get_value<P: IsA<CellRenderer>>(
&self,
renderer: &P,
property_name: &str,
) -> glib::Value;
fn cell_get_value(&self, renderer: &impl IsA<CellRenderer>, property_name: &str)
-> glib::Value;

// rustdoc-stripper-ignore-next
/// Similar to [`Self::cell_get_value`] but panics if the value is of a different type.
#[doc(alias = "gtk_cell_area_cell_get_valist")]
#[doc(alias = "gtk_cell_area_cell_get_property")]
fn cell_get<V: for<'b> FromValue<'b> + 'static, P: IsA<CellRenderer>>(
fn cell_get<V: for<'b> FromValue<'b> + 'static>(
&self,
renderer: &P,
renderer: &impl IsA<CellRenderer>,
property_name: &str,
) -> V;

#[doc(alias = "gtk_cell_area_cell_set_valist")]
#[doc(alias = "gtk_cell_area_cell_set_property")]
fn cell_set<P: IsA<CellRenderer>>(
&self,
renderer: &P,
property_name: &str,
value: &dyn ToValue,
);
fn cell_set(&self, renderer: &impl IsA<CellRenderer>, property_name: &str, value: &dyn ToValue);
}

impl<O: IsA<CellArea>> CellAreaExtManual for O {
Expand All @@ -75,11 +67,11 @@ impl<O: IsA<CellArea>> CellAreaExtManual for O {
self.as_ref().cell_set(renderer, property_name, *value);
});
}
fn activate_cell<P: IsA<Widget>, Q: IsA<CellRenderer>, R: AsRef<Event>>(
fn activate_cell(
&self,
widget: &P,
renderer: &Q,
event: &R,
widget: &impl IsA<Widget>,
renderer: &impl IsA<CellRenderer>,
event: &impl AsRef<Event>,
cell_area: &gdk::Rectangle,
flags: CellRendererState,
) -> bool {
Expand All @@ -95,9 +87,9 @@ impl<O: IsA<CellArea>> CellAreaExtManual for O {
}
}

fn cell_get_value<P: IsA<CellRenderer>>(
fn cell_get_value(
&self,
renderer: &P,
renderer: &impl IsA<CellRenderer>,
property_name: &str,
) -> glib::Value {
unsafe {
Expand All @@ -121,9 +113,9 @@ impl<O: IsA<CellArea>> CellAreaExtManual for O {
}
}

fn cell_get<V: for<'b> FromValue<'b> + 'static, P: IsA<CellRenderer>>(
fn cell_get<V: for<'b> FromValue<'b> + 'static>(
&self,
renderer: &P,
renderer: &impl IsA<CellRenderer>,
property_name: &str,
) -> V {
let value = self.cell_get_value(renderer, property_name);
Expand All @@ -132,9 +124,9 @@ impl<O: IsA<CellArea>> CellAreaExtManual for O {
.expect("Failed to get value of renderer")
}

fn cell_set<P: IsA<CellRenderer>>(
fn cell_set(
&self,
renderer: &P,
renderer: &impl IsA<CellRenderer>,
property_name: &str,
value: &dyn ToValue,
) {
Expand Down Expand Up @@ -165,11 +157,11 @@ impl<O: IsA<CellArea>> CellAreaExtManual for O {
}
}

fn event<P: IsA<CellAreaContext>, Q: IsA<Widget>, R: AsRef<Event>>(
fn event(
&self,
context: &P,
widget: &Q,
event: &R,
context: &impl IsA<CellAreaContext>,
widget: &impl IsA<Widget>,
event: &impl AsRef<Event>,
cell_area: &gdk::Rectangle,
flags: CellRendererState,
) -> i32 {
Expand Down
4 changes: 2 additions & 2 deletions gtk4/src/cell_editable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use glib::IsA;

pub trait CellEditableExtManual {
#[doc(alias = "gtk_cell_editable_start_editing")]
fn start_editing<P: AsRef<gdk::Event>>(&self, event: Option<&P>);
fn start_editing(&self, event: Option<&impl AsRef<gdk::Event>>);
}

impl<O: IsA<CellEditable>> CellEditableExtManual for O {
fn start_editing<P: AsRef<gdk::Event>>(&self, event: Option<&P>) {
fn start_editing(&self, event: Option<&impl AsRef<gdk::Event>>) {
unsafe {
ffi::gtk_cell_editable_start_editing(
self.as_ref().to_glib_none().0,
Expand Down
Loading

0 comments on commit 2a74d32

Please sign in to comment.