[−][src]Crate glib
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.
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.
Re-exports
pub use closure::Closure; |
pub use error::BoolError; |
pub use error::Error; |
pub use object::Cast; |
pub use object::InitiallyUnowned; |
pub use object::InitiallyUnownedClass; |
pub use object::IsA; |
pub use object::IsClassFor; |
pub use object::Object; |
pub use object::ObjectClass; |
pub use object::ObjectExt; |
pub use object::ObjectType; |
pub use object::SendWeakRef; |
pub use object::WeakRef; |
pub use signal::signal_handler_block; |
pub use signal::signal_handler_disconnect; |
pub use signal::signal_handler_unblock; |
pub use signal::signal_stop_emission_by_name; |
pub use signal::SignalHandlerId; |
pub use types::StaticType; |
pub use types::Type; |
pub use value::SendValue; |
pub use value::ToSendValue; |
pub use value::ToValue; |
pub use value::TypedValue; |
pub use value::Value; |
pub use variant::StaticVariantType; |
pub use variant::ToVariant; |
pub use variant::Variant; |
pub use char::*; |
pub use source::*; |
pub use send_unique::SendUnique; |
pub use send_unique::SendUniqueCell; |
Modules
auto | |
boxed |
|
char | |
clone | |
closure | |
error |
|
functions | |
object |
|
prelude | Traits and essential types intended for blanket imports. |
send_unique | |
shared |
|
signal |
|
source | |
subclass | Module containing infrastructure for subclassing |
translate | Translation between GLib/GLib-based FFI types and their Rust counterparts. |
types | Runtime type information. |
value |
|
variant |
|
wrapper |
|
Macros
clone | Macro for passing variables as strong or weak references into a closure. |
g_critical | Macro used to log using GLib logging system. It uses g_log. |
g_debug | Macro used to log using GLib logging system. It uses g_log. |
g_error | Macro used to log using GLib logging system. It uses g_log. |
g_info | Macro used to log using GLib logging system. It uses g_log. |
g_log | Macro used to log using GLib logging system. It uses g_log. |
g_message | Macro used to log using GLib logging system. It uses g_log. |
g_print | Macro used to print messages. It uses g_print. |
g_printerr | Macro used to print error messages. It uses g_printerr. |
g_warning | Macro used to log using GLib logging system. It uses g_log. |
glib_bool_error | Generic error used for functions that fail without any further information |
glib_boxed_wrapper | Wrapper implementations for Boxed types. See |
glib_object_impl | Macro for boilerplate of |
glib_object_interface | Macro for boilerplate of |
glib_object_subclass | Macro for boilerplate of |
glib_object_wrapper | ObjectType implementations for Object types. See |
glib_result_from_gboolean | |
glib_shared_wrapper | Wrapper implementations for shared types. See |
glib_wrapper | Defines a wrapper type and implements the appropriate traits. |
Structs
Binding | |
BindingClass | |
BindingFlags | |
ByteArray | |
Bytes | A shared immutable byte slice (the equivalent of |
Checksum | |
Date | |
DateTime | |
EnumClass | Representation of an |
EnumValue | Representation of a single enum value of an |
FileTest | |
FlagsBuilder | Builder for conveniently setting/unsetting flags and returning a |
FlagsClass | Representation of a |
FlagsValue | Representation of a single flags value of a |
FormatSizeFlags | |
GString | |
IOCondition | |
KeyFile | |
KeyFileFlags | |
LogHandlerId | |
LogLevelFlags | |
LogLevels | |
MainContext | |
MainLoop | |
OptionFlags | |
ParamFlags | |
ParamSpec | |
Quark | |
Receiver | A |
Sender | A |
SignalFlags | |
Source | |
SourceFuture | Represents a |
SourceStream | Represents a |
SpawnFlags | |
String | A mutable text buffer that grows automatically. |
SyncSender | A |
ThreadPool | |
TimeVal | |
TimeZone | |
ValueArray | |
VariantDict |
|
VariantTy | Describes |
VariantType | Describes |
Enums
ChecksumType | |
DateMonth | |
DateWeekday | |
FileError | |
KeyFileError | |
LogLevel | |
OptionArg | |
SeekType | |
TimeType | |
UserDirectory |
Constants
CLONE_MACRO_LOG_DOMAIN | This is the log domain used by the [ |
Statics
Functions
Type Definitions
DateDay | |
DateYear | |
Time | |
TimeSpan |
Attribute Macros
gflags | Attribute macro for defining flags using the |
Derive Macros
GBoxed | Derive macro for defining a |
GEnum |