Crate glib[−][src]
Expand description
Rust GLib and GObject bindings
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.
GLib 2.48 is the lowest supported version for the underlying library.
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
.
Variant
s 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.
Re-exports
pub use ffi; | |
pub use gobject_ffi; | |
pub use self::closure::Closure; | |
pub use self::error::BoolError; | |
pub use self::error::Error; | |
pub use self::object::Cast; | |
pub use self::object::Class; | |
pub use self::object::InitiallyUnowned; | |
pub use self::object::Interface; | |
pub use self::object::IsA; | |
pub use self::object::Object; | |
pub use self::object::ObjectExt; | |
pub use self::object::ObjectType; | |
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::SignalHandlerId; | |
pub use self::types::ILong; | |
pub use self::types::StaticType; | |
pub use self::types::Type; | |
pub use self::types::ULong; | |
pub use self::value::BoxedValue; | |
pub use self::value::SendValue; | |
pub use self::value::ToSendValue; | |
pub use self::value::ToValue; | |
pub use self::value::Value; | |
pub use self::variant::FromVariant; | |
pub use self::variant::StaticVariantType; | |
pub use self::variant::ToVariant; | |
pub use self::variant::Variant; | |
pub use self::char::*; | |
pub use self::source::*; | |
pub use self::send_unique::SendUnique; | |
pub use self::send_unique::SendUniqueCell; |
Modules
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
bool_error | Generic error used for functions that fail without any further information |
clone | Macro for passing variables as strong or weak references into a closure. |
debug | log_macros A macro which behaves exactly as |
error | log_macros A macro which behaves exactly as |
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_boxed_wrapper | Wrapper implementations for Boxed types. See |
glib_object_wrapper | ObjectType implementations for Object types. See |
glib_shared_wrapper | Wrapper implementations for shared types. See |
info | log_macros A macro which behaves exactly as |
result_from_gboolean | |
trace | log_macros A macro which behaves exactly as |
warn | log_macros A macro which behaves exactly as |
wrapper | Defines a wrapper type and implements the appropriate traits. |
Structs
Array | |
Binding | |
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 |
FileSetContentsFlags | |
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 | |
GlibLogger | An implementation of a |
IOCondition | |
KeyFile | |
KeyFileFlags | |
LogHandlerId | |
LogLevelFlags | |
LogLevels | |
MainContext | |
MainLoop | |
OptionFlags | |
ParamFlags | |
ParamSpec | |
ParamSpecBoolean | |
ParamSpecBoxed | |
ParamSpecChar | |
ParamSpecDouble | |
ParamSpecEnum | |
ParamSpecFlags | |
ParamSpecFloat | |
ParamSpecGType | |
ParamSpecInt | |
ParamSpecInt64 | |
ParamSpecLong | |
ParamSpecObject | |
ParamSpecOverride | |
ParamSpecParam | |
ParamSpecPointer | |
ParamSpecString | |
ParamSpecUChar | |
ParamSpecUInt | |
ParamSpecUInt64 | |
ParamSpecULong | |
ParamSpecUnichar | |
ParamSpecValueArray | |
ParamSpecVariant | |
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 | |
TimeZone | |
Uri | |
UriFlags | |
UriHideFlags | |
UriParamsFlags | |
ValueArray | |
VariantDict |
|
VariantIter | Iterator over items in a variant. |
VariantTy | Describes |
VariantType | Describes |
Enums
ChecksumType | |
DateMonth | |
DateWeekday | |
FileError | |
GlibLoggerDomain | Enumeration of the possible domain handling behaviours for a
|
GlibLoggerFormat | Enumeration of the possible formatting behaviours for a
|
KeyFileError | |
LogLevel | |
OptionArg | |
SeekType | |
TimeType | |
UriError | v2_66 |
UserDirectory |
Constants
CLONE_MACRO_LOG_DOMAIN | This is the log domain used by the |
Statics
Traits
ParamSpecType |
Functions
Type Definitions
DateDay | |
DateYear | |
Time | |
TimeSpan |
Attribute Macros
gflags | Attribute macro for defining flags using the |
object_interface | Macro for boilerplate of |
object_subclass | Macro for boilerplate of |
Derive Macros
Downgrade | Macro for deriving implementations of |
GBoxed | Derive macro for defining a |
GEnum | |
GErrorDomain | Derive macro for defining a GLib error domain and its associated
|
GSharedBoxed | Derive macro for defining a |