21 releases

0.7.1 Feb 25, 2019
0.6.1 Dec 14, 2018
0.6.0 Sep 9, 2018
0.5.0 Mar 17, 2018
0.0.3 Jul 18, 2015

#4 in GUI

Download history 2041/week @ 2018-12-20 1542/week @ 2018-12-27 2167/week @ 2019-01-03 2053/week @ 2019-01-10 2122/week @ 2019-01-17 2003/week @ 2019-01-24 1888/week @ 2019-01-31 1672/week @ 2019-02-07 2336/week @ 2019-02-14 3216/week @ 2019-02-21 2546/week @ 2019-02-28 3988/week @ 2019-03-07 3551/week @ 2019-03-14 3072/week @ 2019-03-21 3102/week @ 2019-03-28

11,106 downloads per month
Used in 117 crates (72 directly)

MIT license

631KB
13K 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.

License

MIT


lib.rs:

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

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

Objects

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.

For creating new subclasses of Object or other object types this crate has to be compiled with the subclassing feature to enable the subclass module. Check 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.

Dependencies

~695KB
~13K SLoC