Rust: The state of the bindings

Slides at bilelmoussaoui.github.io/guadec-2023/

Presentation
  • Software Engineer at Red Hat
  • GNOME Developer
  • Maintains too many Rust crates
What are the Rust bindings?
  • Wrappers of the GObject based C libraries
  • Safe and convenient to use
  • Mostly automatically generated code with gir
Which bindings exists?
  • gtk-rs-core: glib/gio, pango, cairo, graphene
  • gtk4-rs: libadwaita, gtksourceview, libshumate, webkit6, libpanel, libspelling
  • gtk3-rs: in maintenance mode
  • others: poppler, soup3...
Who uses them?
Who uses them?
Who uses them?
What about the rest of the platform?
What changed since last time?

GtkBuilderScope integration

					#[gtk::template_callbacks]
impl MyWidget {
	#[template_callback]
	fn button_clicked(&self, button: &gtk::Button) {
		println!("button clicked!")
	}

	#[template_callback]
	async fn some_other_callback(&self, button: &gtk::Button) {
		use ashpd::desktop::screenshot::Color;
		let color = Color::request().send().await.unwrap().response().unwrap();
		println!("{:#?}", color)
	}
}
				
What changed since last time?

Procedural macro for generating GObject properties boilerplate

					#[derive(glib::Properties, Default)]
#[properties(wrapper_type = super::CustomObject)]
pub struct CustomObject {
	#[property(get, set = Self::set_prop, construct)]
	prop: RefCell<String>,
}

#[glib::derived_properties]
impl ObjectImpl for CustomObject {}

impl CustomObject {
	fn set_prop(&self, value: &str) {
		*self.prop.borrow_mut() = format!("custom set: {}", value);
	}
}
				
What changed since last time?

gdk4-win32 bindings

What changed since last time?

Reduced allocations by introductions various collections types: glib::List,glib::SList, glib::Strv

What changed since last time?
  • Improved documentations
    • List of properties and signals
    • Virtual and class methods support
  • More chapters in the gtk4-rs book
What to look forward to?
  • More procedural macros: signals, improved glib::wrapper!
  • i18n support without going through gettext-rs
  • Reduce allocations when interacting with strings / collections
  • Support the new introspection annotations
What to look forward to?

A new release!

Reach out

Thank you!

Any questions?