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 #1929

Open
wants to merge 7 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
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,15 @@ gsk = {package = "gsk4", path = "gsk4", version = "0.10"}
gtk4-macros = {path = "gtk4-macros", version = "0.10"}
gtk4-sys = {path = "gtk4/sys", version = "0.10"}
gtk = { path = "gtk4", package = "gtk4", version = "0.10" }


[patch.'https://github.com/gtk-rs/gtk-rs-core']
glib-sys = { git = "https://github.com/fengalin/gtk-rs-core", branch = "more-into-option-args" }
gobject-sys = { git = "https://github.com/fengalin/gtk-rs-core", branch = "more-into-option-args" }
glib = { git = "https://github.com/fengalin/gtk-rs-core", branch = "more-into-option-args" }
gio-sys = { git = "https://github.com/fengalin/gtk-rs-core", branch = "more-into-option-args" }
gio = { git = "https://github.com/fengalin/gtk-rs-core", branch = "more-into-option-args" }
cairo-sys-rs = { git = "https://github.com/fengalin/gtk-rs-core", branch = "more-into-option-args" }
cairo-rs = { git = "https://github.com/fengalin/gtk-rs-core", branch = "more-into-option-args" }
pango-sys = { git = "https://github.com/fengalin/gtk-rs-core", branch = "more-into-option-args" }
pango = { git = "https://github.com/fengalin/gtk-rs-core", branch = "more-into-option-args" }
2 changes: 1 addition & 1 deletion examples/column_view_datagrid/grid_cell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ impl Default for GridCell {

impl GridCell {
pub fn set_entry(&self, entry: &Entry) {
self.imp().name.set_text(Some(&entry.name));
self.imp().name.set_text(entry.name.as_str());
}
}
2 changes: 1 addition & 1 deletion examples/custom_orientable/custom_orientable/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl ObjectImpl for CustomOrientable {
}

fn dispose(&self) {
// Child widgets need to be manually unparented in `dispose()`.
// Child widgets need to be manually un-parented in `dispose()`.
if let Some(child) = self.first_label.borrow_mut().take() {
child.unparent();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_widget/ex_button/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl ObjectImpl for ExButton {
}

fn dispose(&self) {
// Child widgets need to be manually unparented in `dispose()`.
// Child widgets need to be manually un-parented in `dispose()`.
if let Some(child) = self.child.borrow_mut().take() {
child.unparent();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/dialog/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async fn dialog<W: IsA<gtk::Window>>(window: W) {
let info_dialog = gtk::AlertDialog::builder()
.modal(true)
.message("You answered")
.detail(format!("Your answer: {answer:?}"))
.detail(format!("Your answer: {answer:?}").as_str())
.build();

info_dialog.show(Some(&window));
Expand Down
4 changes: 2 additions & 2 deletions examples/list_view_apps_launcher/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ fn build_ui(app: &gtk::Application) {
let parent_window = list_view.root().and_downcast::<gtk::Window>().unwrap();

gtk::AlertDialog::builder()
.message(format!("Failed to start {}", app_info.name()))
.detail(err.to_string())
.message(format!("Failed to start {}", app_info.name()).as_str())
.detail(err.to_string().as_str())
.modal(true)
.build()
.show(Some(&parent_window));
Expand Down
2 changes: 1 addition & 1 deletion examples/tokio_async_request/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn build_ui(app: &Application) {
match response {
Ok(response) => {
for pokemon in response {
let label = gtk::Label::new(Some(&pokemon.name));
let label = gtk::Label::new(pokemon.name.as_str());
label.set_halign(gtk::Align::Start);
list_box.append(&label);
}
Expand Down
2 changes: 1 addition & 1 deletion gdk4-macos/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 @ c05f5cc23cb7)
2 changes: 1 addition & 1 deletion gdk4-macos/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 @ c05f5cc23cb7)
2 changes: 1 addition & 1 deletion gdk4-wayland/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 @ c05f5cc23cb7)
2 changes: 1 addition & 1 deletion gdk4-wayland/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 @ c05f5cc23cb7)
2 changes: 1 addition & 1 deletion gdk4-win32/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 @ c05f5cc23cb7)
4 changes: 2 additions & 2 deletions gdk4-win32/src/auto/win32_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ impl Win32Display {
}

#[doc(alias = "gdk_win32_display_set_cursor_theme")]
pub fn set_cursor_theme(&self, name: Option<&str>, size: i32) {
pub fn set_cursor_theme<'a>(&self, name: impl Into<Option<&'a str>>, size: i32) {
unsafe {
ffi::gdk_win32_display_set_cursor_theme(
self.to_glib_none().0,
name.to_glib_none().0,
name.into().to_glib_none().0,
size,
);
}
Expand Down
2 changes: 1 addition & 1 deletion gdk4-win32/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 @ c05f5cc23cb7)
4 changes: 2 additions & 2 deletions gdk4-x11/src/auto/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ pub fn x11_get_server_time(surface: &X11Surface) -> u32 {
}

#[doc(alias = "gdk_x11_set_sm_client_id")]
pub fn x11_set_sm_client_id(sm_client_id: Option<&str>) {
pub fn x11_set_sm_client_id<'a>(sm_client_id: impl Into<Option<&'a str>>) {
assert_initialized_main_thread!();
unsafe {
ffi::gdk_x11_set_sm_client_id(sm_client_id.to_glib_none().0);
ffi::gdk_x11_set_sm_client_id(sm_client_id.into().to_glib_none().0);
}
}
2 changes: 1 addition & 1 deletion gdk4-x11/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 @ c05f5cc23cb7)
6 changes: 4 additions & 2 deletions gdk4-x11/src/auto/x11_device_manager_xi2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ impl X11DeviceManagerXI2Builder {
}
}

pub fn display(self, display: &impl IsA<gdk::Display>) -> Self {
pub fn display<'a, P: IsA<gdk::Display>>(self, display: impl Into<Option<&'a P>>) -> Self {
Self {
builder: self.builder.property("display", display.clone().upcast()),
builder: self
.builder
.property("display", display.into().as_ref().map(|p| p.as_ref())),
}
}

Expand Down
16 changes: 9 additions & 7 deletions gdk4-x11/src/auto/x11_device_xi2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ impl X11DeviceXI2Builder {
}
}

pub fn display(self, display: &impl IsA<gdk::Display>) -> Self {
pub fn display<'a, P: IsA<gdk::Display>>(self, display: impl Into<Option<&'a P>>) -> Self {
Self {
builder: self.builder.property("display", display.clone().upcast()),
builder: self
.builder
.property("display", display.into().as_ref().map(|p| p.as_ref())),
}
}

Expand All @@ -63,7 +65,7 @@ impl X11DeviceXI2Builder {
}
}

pub fn name(self, name: impl Into<glib::GString>) -> Self {
pub fn name<'a>(self, name: impl Into<Option<&'a str>>) -> Self {
Self {
builder: self.builder.property("name", name.into()),
}
Expand All @@ -75,15 +77,15 @@ impl X11DeviceXI2Builder {
}
}

pub fn product_id(self, product_id: impl Into<glib::GString>) -> Self {
pub fn product_id<'a>(self, product_id: impl Into<Option<&'a str>>) -> Self {
Self {
builder: self.builder.property("product-id", product_id.into()),
}
}

pub fn seat(self, seat: &gdk::Seat) -> Self {
pub fn seat<'a>(self, seat: impl Into<Option<&'a gdk::Seat>>) -> Self {
Self {
builder: self.builder.property("seat", seat.clone()),
builder: self.builder.property("seat", seat.into()),
}
}

Expand All @@ -93,7 +95,7 @@ impl X11DeviceXI2Builder {
}
}

pub fn vendor_id(self, vendor_id: impl Into<glib::GString>) -> Self {
pub fn vendor_id<'a>(self, vendor_id: impl Into<Option<&'a str>>) -> Self {
Self {
builder: self.builder.property("vendor-id", vendor_id.into()),
}
Expand Down
14 changes: 9 additions & 5 deletions gdk4-x11/src/auto/x11_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ glib::wrapper! {

impl X11Display {
//#[doc(alias = "gdk_x11_display_broadcast_startup_message")]
//pub fn broadcast_startup_message(&self, message_type: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
//pub fn broadcast_startup_message(&self, message_type: &str, : /*Unimplemented*/Basic: VarArgs) {
// unsafe { TODO: call ffi:gdk_x11_display_broadcast_startup_message() }
//}

Expand Down Expand Up @@ -134,11 +134,11 @@ impl X11Display {
#[cfg_attr(feature = "v4_16", deprecated = "Since 4.16")]
#[allow(deprecated)]
#[doc(alias = "gdk_x11_display_set_cursor_theme")]
pub fn set_cursor_theme(&self, theme: Option<&str>, size: i32) {
pub fn set_cursor_theme<'a>(&self, theme: impl Into<Option<&'a str>>, size: i32) {
unsafe {
ffi::gdk_x11_display_set_cursor_theme(
self.to_glib_none().0,
theme.to_glib_none().0,
theme.into().to_glib_none().0,
size,
);
}
Expand Down Expand Up @@ -222,8 +222,12 @@ impl X11Display {
}

#[doc(alias = "gdk_x11_display_open")]
pub fn open(display_name: Option<&str>) -> Option<gdk::Display> {
pub fn open<'a>(display_name: impl Into<Option<&'a str>>) -> Option<gdk::Display> {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gdk_x11_display_open(display_name.to_glib_none().0)) }
unsafe {
from_glib_full(ffi::gdk_x11_display_open(
display_name.into().to_glib_none().0,
))
}
}
}
4 changes: 2 additions & 2 deletions gdk4-x11/src/auto/x11_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ impl X11Surface {
}

#[doc(alias = "gdk_x11_surface_set_utf8_property")]
pub fn set_utf8_property(&self, name: &str, value: Option<&str>) {
pub fn set_utf8_property<'a>(&self, name: &str, value: impl Into<Option<&'a str>>) {
unsafe {
ffi::gdk_x11_surface_set_utf8_property(
self.to_glib_none().0,
name.to_glib_none().0,
value.to_glib_none().0,
value.into().to_glib_none().0,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion gdk4-x11/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 @ c05f5cc23cb7)
Loading
Loading