Expand description
§Rust GLib and GObject bindings
Rust bindings and wrappers for GLib, part of gtk-rs-core.
GLib 2.56 is the lowest supported version for the underlying library.
This library contains bindings to GLib and GObject types and APIs as well as 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.
§Minimum supported Rust version
Currently, the minimum supported Rust version is 1.70.0.
§Dynamic typing
Most types in the GLib family have Type identifiers.
Their corresponding Rust types implement the [StaticType] trait.
A dynamically typed Value can carry values of any [StaticType].
Variants can carry values of [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 or
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 if 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] or 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
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.
§Documentation
§Using
We recommend using crates from crates.io, as demonstrated here.
If you want to track the bleeding edge, use the git dependency instead:
[dependencies]
glib = { git = "https://github.com/gtk-rs/gtk-rs-core.git", package = "glib" }
Avoid mixing versioned and git crates like this:
# This will not compile
[dependencies]
glib = "0.13"
glib = { git = "https://github.com/gtk-rs/gtk-rs-core.git", package = "glib" }
§License
glib is available under the MIT License, please refer to it.
Re-exports§
- pub use self::closure::Closure;
- pub use self::closure::RustClosure;
- pub use self::enums::EnumClass;
- pub use self::enums::EnumValue;
- pub use self::enums::FlagsBuilder;
- pub use self::enums::FlagsClass;
- pub use self::enums::FlagsValue;
- pub use self::enums::UserDirectory;
- pub use self::error::BoolError;
- pub use self::error::Error;
- pub use self::object::BorrowedObject;
- pub use self::object::Class;
- pub use self::object::InitiallyUnowned;
- pub use self::object::Interface;
- pub use self::object::Object;
- pub use self::object::SendWeakRef;
- pub use self::object::WeakRef;
- pub use self::signal::signal_handler_block;
- pub use self::signal::signal_handler_disconnect;
- pub use self::signal::signal_handler_unblock;
- pub use self::signal::signal_stop_emission_by_name;
- pub use self::signal::Propagation;
- pub use self::signal::SignalHandlerId;
- pub use self::types::ILong;
- pub use self::types::Pointer;
- pub use self::types::Type;
- pub use self::types::ULong;
- pub use self::value::BoxedValue;
- pub use self::value::SendValue;
- pub use self::value::Value;
- pub use self::variant::FixedSizeVariantArray;
- pub use self::variant::Variant;
- pub use self::FileError;
- pub use collections::List;
- pub use collections::PtrSlice;
- pub use collections::SList;
- pub use collections::Slice;
- pub use collections::StrV;
- pub use self::char::Char;
- pub use self::char::UChar;
- pub use self::match_info::MatchInfo;
- pub use bitflags;
- pub use ffi;
- pub use gobject_ffi;
- pub use self::source::*;
Modules§
- IMPLBoxed wrapper implementation.
- IMPLBoxedInline wrapper implementation.
- Errorbinding and helper trait.
- IMPLObject wrapper implementation and- Objectbinding.
- Traits and essential types intended for blanket imports.
- This module is inefficient and should not be used by Rust programs except for compatibility with GLib.Regex based APIs.
- IMPLShared (reference counted) wrapper implementation.
- IMPLLow level signal support.
- Module containing infrastructure for subclassingGObjects and registering boxed types.
- Translation between GLib/GLib-based FFI types and their Rust counterparts.
- Runtime type information.
- Valuebinding and helper traits.
- Variantbinding and helper traits.
- IMPLThe- wrapper!macro and miscellaneous wrapper traits.
Macros§
- Generic error used for functions that fail without any further information
- Macro for passing variables as strong or weak references into a closure.
- Macro for creating aClosureobject. This is a wrapper aroundClosure::newthat automatically type checks its arguments at run-time.
- The same asclosure!but usesClosure::new_localas a constructor. This is useful for closures which can’t be sent across threads. See the documentation ofclosure!for details.
- This macro returns the name of the enclosing function. As the internal implementation is based on thestd::any::type_name, this macro derives all the limitations of this function.
- Macro used to log using GLib logging system. It uses g_log.
- Macro used to log using GLib logging system. It uses g_log.
- Macro used to log using GLib logging system. It uses g_log.
- Macro used to log using GLib logging system. It uses g_log.
- Macro used to log using GLib logging system. It uses g_log.
- Macro used to log using GLib logging system. It uses g_log.
- Macro used to print messages. It uses g_print.
- Macro used to print error messages. It uses g_printerr.
- Macro used to log using GLib logging system. It uses g_log.
- Creates aGStringusing interpolation of runtime expressions.
- Wrapper implementations for BoxedInline types. Seewrapper!.
- Wrapper implementations for Boxed types. Seewrapper!.
- ObjectType implementations for Object types. Seewrapper!.
- Wrapper implementations for shared types. Seewrapper!.
- Converts a static string literal into a static nul-terminated string.
- Macro used to log using GLib structured logging system.
- Defines a wrapper type and implements the appropriate traits.
Structs§
- This is a subclass ofglib::object::Objectcapable of storing any Rust type. It let’s you insert a Rust type anywhere aglib::object::Objectis needed. The inserted value can then be borrowed as a Rust type, by using the various provided methods.
- A shared immutable byte slice (the equivalent ofRc<[u8]>).
- ACollationKeyallows ordering strings using the linguistically correct rules for the current locale.
- AFilenameCollationKeyallows ordering file names using the linguistically correct rules for the current locale. Compared toCollationKey, filename collation keys take into consideration dots and other characters commonly found in file names.
- The error returned when a future times out.
- Representation of a borrowedGString.
- Error type indicating that a buffer had unexpected nul-bytes.
- A type representing an owned, C-compatible, nul-terminated UTF-8 string.
- A mutable text buffer that grows automatically.
- Error type indicating that a buffer had unexpected nul-bytes.
- Error type indicating that a buffer did not have a trailing nul-byte.
- NULL-terminated UTF-8 string as stored in [- StrV].
- Error type indicating that a buffer had invalid UTF-8.
- Task failure from awaiting aJoinHandle.
- A handle to a task running on aMainContext.
- Structure representing a single field in a structured log entry.
- Represents aFuturearound aglib::Source. The future will be resolved once the source has provided a value
- Represents aStreamaround aglib::Source. The stream will be provide all values that are provided by the source
- Variant ofJoinHandlethat is returned fromMainContext::spawn_from_within.
- A handle to a thread running on aThreadPool.
- A value representing an interval of time, in microseconds.
- VariantDictis a mutable key/value store where the keys are always strings and the values are- Variants.
- Iterator over items in a variant.
- Iterator over items in a variant of typeas.
- DescribesVarianttypes.
- An iterator over the individual components of a tuple VariantTy.
- DescribesVarianttypes.
Enums§
- The result of a single step of the Unicode canonical decomposition algorithm
- Continue calling the closure in the future iterations or drop it.
- A wrapper forConvertErrorthat can hold an offset into the input string.
- The kind of decomposition to perform
- Error type holding all possible failures when creating aGStrreference.
- Error type holding all possible failures when creating aGString.
- A wrapper forstd::io::Errorthat can hold an offset into an input string.
Constants§
- This is the log domain used by theclone!macro. If you want to use a custom logger (it prints to stdout by default), you can set your own logger using the correspondinglogfunctions.
Statics§
Traits§
- A trait implemented by the variousParamSpecbuilder types.
- This trait provides access to Unicode character classification and manipulations functions provided by GLib that do not exist in the standard library
Functions§
- Obtain the character set for the current locale.
- Create aFuturethat will resolve once the child process with the given pid exits
- Create aFuturethat will resolve once the child process with the given pid exits
- Add a timeout to aFuture.
- Add a timeout to aFuture.
- Create aStreamthat will provide a value every given number of milliseconds.
- Create aStreamthat will provide a value every given number of seconds.
- Create aStreamthat will provide a value every given number of seconds.
- Create aStreamthat will provide a value every given number of milliseconds.
- To set back the default print handler, use thelog_unset_default_handlerfunction.
- To set the default print handler, use thelog_set_default_handlerfunction.
- Same asget_prgname().
- To set back the default print handler, use theunset_print_handlerfunction.
- To set back the default print handler, use theunset_printerr_handlerfunction.
- Same asset_prgname().
- Spawn a new infallibleFutureon the thread-default main context.
- Spawn a new infallibleFutureon the thread-default main context.
- Create aFuturethat will resolve after the given number of milliseconds.
- Create aFuturethat will resolve after the given number of seconds.
- Create aFuturethat will resolve after the given number of seconds.
- Create aFuturethat will resolve after the given number of milliseconds.
- Create aFuturethat will resolve once the given UNIX signal is raised
- Create aFuturethat will resolve once the given UNIX signal is raised
- Create aStreamthat will provide a value whenever the given UNIX signal is raised
- Create aStreamthat will provide a value whenever the given UNIX signal is raised
- To set the default print handler, use theset_print_handlerfunction.
- To set the default print handler, use theset_printerr_handlerfunction.
Type Aliases§
Attribute Macros§
- When applied toObjectImpl
- Attribute macro for defining flags using thebitflagscrate. This macro will also define aGFlags::type_function and theglib::Valuetraits.
- Macro for boilerplate ofObjectInterfaceimplementations.
- Macro for boilerplate ofObjectSubclassimplementations.
Derive Macros§
- Derive macro for defining aBoxedType::type_function and theglib::Valuetraits. Optionally, the type can be marked asnullableto get an implementation ofglib::value::ToValueOptional.
- Macro for deriving implementations ofglib::clone::Downgradeandglib::clone::Upgradetraits and a weak type.
- Derive macro for register a Rust enum in the GLib type system and derive the theglib::Valuetraits.
- Derive macro for defining a GLib error domain and its associatedErrorDomaintrait.
- This macro enables you to derive object properties in a quick way.
- Derive macro for defining aSharedType::get_typefunction and theglib::Valuetraits. Optionally, the type can be marked asnullableto get an implementation ofglib::value::ToValueOptional.
- Example
- Derive macro for serializing/deserializing custom structs/enums asglib::Variants.