31 releases

Uses old Rust 2015

new 0.10.3 Oct 14, 2020
0.10.1 Jul 7, 2020
0.9.3 Feb 14, 2020
0.9.0 Dec 14, 2019
0.0.3 Jul 18, 2015

#346 in GUI

Download history 6046/week @ 2020-06-28 6700/week @ 2020-07-05 5862/week @ 2020-07-12 5587/week @ 2020-07-19 5028/week @ 2020-07-26 4912/week @ 2020-08-02 5859/week @ 2020-08-09 6124/week @ 2020-08-16 6933/week @ 2020-08-23 6762/week @ 2020-08-30 6981/week @ 2020-09-06 6910/week @ 2020-09-13 6061/week @ 2020-09-20 8604/week @ 2020-09-27 8661/week @ 2020-10-04 8181/week @ 2020-10-11

28,027 downloads per month
Used in 223 crates (138 directly)

MIT license

18K SLoC

glib Build Status Build status Gitter

GLib bindings for Rust.

Alongside GLib bindings, this crate also includes the infrastructure to subclass GObject for extending libraries like GTK+. A code example can be found in the documentation of this crate in the subclass module.




glib, gobject and gio bindings for Rust

This library contains

  • bindings to some essential GLib, GObject, GIO types and APIs,

  • common building blocks used in both handmade and machine generated bindings to GTK+ and other GLib-based libraries.

It is the foundation for higher level libraries with uniform Rusty (safe and strongly typed) APIs. It avoids exposing GLib-specific data types where possible and is not meant to provide comprehensive GLib bindings, which would often amount to duplicating the Rust Standard Library or other utility crates.

The library is a work in progress: expect missing functionality and breaking changes.

Dynamic typing

Most types in the GLib family have type identifiers (Type). Their corresponding Rust types implement the StaticType trait.

Dynamically typed Value can carry values of any T: StaticType.

Variant can carry values of T: StaticVariantType.


Errors are represented by Error, which can carry values from various error domains (such as FileError).


Each class and interface has a corresponding smart pointer struct representing an instance of that type (e.g. Object for GObject, gtk::Widget for GtkWidget). They are reference counted and feature interior mutability similarly to Rust's Rc<RefCell<T>> idiom. Consequently, cloning objects is cheap and their methods never require mutable borrows. Two smart pointers are equal iff they point to the same object.

The root of the object hierarchy is Object. Inheritance and subtyping is denoted with the IsA marker trait. The Cast trait enables upcasting and downcasting.

Interfaces and non-leaf classes also have corresponding traits (e.g. ObjectExt and gtk::WidgetExt), which are blanketly implemented for all their subtypes.

You can create new subclasses of Object or other object types. Look at the module's documentation for further details and a code example.

Under the hood

GLib-based libraries largely operate on pointers to various boxed or reference counted structures so the bindings have to implement corresponding smart pointers (wrappers), which encapsulate resource management and safety checks. Such wrappers are defined via the glib_wrapper! macro, which uses abstractions defined in the wrapper, boxed, shared and object modules.

The translate module defines and partly implements conversions between high level Rust types (including the aforementioned wrappers) and their FFI counterparts.


~73K SLoC