Expand description
§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.
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 send_unique::SendUnique;
pub use send_unique::SendUniqueCell;
pub use self::constants::CSET_a_2_z;
pub use self::constants::CSET_A_2_Z;
pub use self::constants::CSET_DIGITS;
pub use self::constants::KEY_FILE_DESKTOP_ACTION_GROUP_PREFIX;
pub use self::constants::KEY_FILE_DESKTOP_GROUP;
pub use self::constants::KEY_FILE_DESKTOP_KEY_ACTIONS;
pub use self::constants::KEY_FILE_DESKTOP_KEY_CATEGORIES;
pub use self::constants::KEY_FILE_DESKTOP_KEY_COMMENT;
pub use self::constants::KEY_FILE_DESKTOP_KEY_DBUS_ACTIVATABLE;
pub use self::constants::KEY_FILE_DESKTOP_KEY_EXEC;
pub use self::constants::KEY_FILE_DESKTOP_KEY_FULLNAME;
pub use self::constants::KEY_FILE_DESKTOP_KEY_GENERIC_NAME;
pub use self::constants::KEY_FILE_DESKTOP_KEY_GETTEXT_DOMAIN;
pub use self::constants::KEY_FILE_DESKTOP_KEY_HIDDEN;
pub use self::constants::KEY_FILE_DESKTOP_KEY_ICON;
pub use self::constants::KEY_FILE_DESKTOP_KEY_KEYWORDS;
pub use self::constants::KEY_FILE_DESKTOP_KEY_MIME_TYPE;
pub use self::constants::KEY_FILE_DESKTOP_KEY_NAME;
pub use self::constants::KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN;
pub use self::constants::KEY_FILE_DESKTOP_KEY_NO_DISPLAY;
pub use self::constants::KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN;
pub use self::constants::KEY_FILE_DESKTOP_KEY_PATH;
pub use self::constants::KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY;
pub use self::constants::KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS;
pub use self::constants::KEY_FILE_DESKTOP_KEY_TERMINAL;
pub use self::constants::KEY_FILE_DESKTOP_KEY_TRY_EXEC;
pub use self::constants::KEY_FILE_DESKTOP_KEY_TYPE;
pub use self::constants::KEY_FILE_DESKTOP_KEY_URL;
pub use self::constants::KEY_FILE_DESKTOP_KEY_VERSION;
pub use self::constants::KEY_FILE_DESKTOP_TYPE_APPLICATION;
pub use self::constants::KEY_FILE_DESKTOP_TYPE_DIRECTORY;
pub use self::constants::KEY_FILE_DESKTOP_TYPE_LINK;
pub use self::constants::OPTION_REMAINING;
pub use self::constants::STR_DELIMITERS;
pub use self::constants::URI_RESERVED_CHARS_GENERIC_DELIMITERS;
pub use self::constants::URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS;
pub use char::*;
pub use source::*;
Modules§
- boxed
IMPL
Boxed wrapper implementation.- char
- closure
- error
Error
binding and helper trait.- functions
- object
IMPL
Object wrapper implementation andObject
binding.- prelude
- Traits and essential types intended for blanket imports.
- send_
unique - shared
IMPL
Shared (reference counted) wrapper implementation.- signal
IMPL
Low level signal support.- source
- translate
- Translation between GLib/GLib-based FFI types and their Rust counterparts.
- types
- Runtime type information.
- value
Value
binding and helper traits.- variant
Variant
binding and helper traits.- wrapper
IMPL
Theglib_wrapper!
macro and miscellaneous wrapper traits.
Macros§
- glib_
bool_ error - Generic error used for functions that fail without any further information
- glib_
boxed_ wrapper - Wrapper implementations for Boxed types. See
glib_wrapper!
. - glib_
object_ wrapper - ObjectType implementations for Object types. See
glib_wrapper!
. - glib_
result_ from_ gboolean - glib_
shared_ wrapper - Wrapper implementations for shared types. See
glib_wrapper!
. - glib_
wrapper - Defines a wrapper type and implements the appropriate traits.
Structs§
- Binding
- Binding
Class - Binding
Flags - Byte
Array - Bytes
- A shared immutable byte slice (the equivalent of
Rc<[u8]>
). - CSET_
A_ 2_ Z - CSET_
DIGITS - CSET_
a_ 2_ z - Checksum
- Date
- Date
Time - Enum
Class - Representation of an
enum
for dynamically, at runtime, querying the values of the enum and using them. - Enum
Value - Representation of a single enum value of an
EnumClass
. - File
Test - Flags
Builder - Builder for conveniently setting/unsetting flags and returning a
Value
. - Flags
Class - Representation of a
flags
for dynamically, at runtime, querying the values of the enum and using them - Flags
Value - Representation of a single flags value of a
FlagsClass
. - Format
Size Flags - IOCondition
- KEY_
FILE_ DESKTOP_ ACTION_ GROUP_ PREFIX - KEY_
FILE_ DESKTOP_ GROUP - KEY_
FILE_ DESKTOP_ KEY_ ACTIONS - KEY_
FILE_ DESKTOP_ KEY_ CATEGORIES - KEY_
FILE_ DESKTOP_ KEY_ COMMENT - KEY_
FILE_ DESKTOP_ KEY_ DBUS_ ACTIVATABLE - KEY_
FILE_ DESKTOP_ KEY_ EXEC - KEY_
FILE_ DESKTOP_ KEY_ FULLNAME - KEY_
FILE_ DESKTOP_ KEY_ GENERIC_ NAME - KEY_
FILE_ DESKTOP_ KEY_ GETTEXT_ DOMAIN - KEY_
FILE_ DESKTOP_ KEY_ HIDDEN - KEY_
FILE_ DESKTOP_ KEY_ ICON - KEY_
FILE_ DESKTOP_ KEY_ KEYWORDS - KEY_
FILE_ DESKTOP_ KEY_ MIME_ TYPE - KEY_
FILE_ DESKTOP_ KEY_ NAME - KEY_
FILE_ DESKTOP_ KEY_ NOT_ SHOW_ IN - KEY_
FILE_ DESKTOP_ KEY_ NO_ DISPLAY - KEY_
FILE_ DESKTOP_ KEY_ ONLY_ SHOW_ IN - KEY_
FILE_ DESKTOP_ KEY_ PATH - KEY_
FILE_ DESKTOP_ KEY_ STARTUP_ NOTIFY - KEY_
FILE_ DESKTOP_ KEY_ STARTUP_ WM_ CLASS - KEY_
FILE_ DESKTOP_ KEY_ TERMINAL - KEY_
FILE_ DESKTOP_ KEY_ TRY_ EXEC - KEY_
FILE_ DESKTOP_ KEY_ TYPE - KEY_
FILE_ DESKTOP_ KEY_ URL - KEY_
FILE_ DESKTOP_ KEY_ VERSION - KEY_
FILE_ DESKTOP_ TYPE_ APPLICATION - KEY_
FILE_ DESKTOP_ TYPE_ DIRECTORY - KEY_
FILE_ DESKTOP_ TYPE_ LINK - KeyFile
- KeyFile
Flags - Main
Context - Main
Loop - OPTION_
REMAINING - Option
Flags - Param
Flags - Param
Spec - Quark
- Receiver
- A
Receiver
that can be attached to a main context to receive items from its correspondingSender
orSyncSender
. - STR_
DELIMITERS - Sender
- A
Sender
that can be used to send items to the corresponding main context receiver. - Signal
Flags - Source
- Spawn
Flags - String
- A mutable text buffer that grows automatically.
- Sync
Sender - A
SyncSender
that can be used to send items to the corresponding main context receiver. - TimeVal
- Time
Zone - URI_
RESERVED_ CHARS_ GENERIC_ DELIMITERS - URI_
RESERVED_ CHARS_ SUBCOMPONENT_ DELIMITERS - Value
Array - Variant
Ty - Describes
Variant
types. - Variant
Type - Describes
Variant
types.
Enums§
Functions§
- access
- assert_
warning - assertion_
message - assertion_
message_ cmpstr - base64_
decode - base64_
encode - bit_
nth_ lsf - bit_
nth_ msf - bit_
storage - build_
filenamev - build_
pathv - chdir
- check_
version - clear_
error - compute_
checksum_ for_ bytes - compute_
checksum_ for_ data - compute_
checksum_ for_ string - compute_
hmac_ for_ data - compute_
hmac_ for_ string - dcgettext
- dgettext
- dngettext
- dpgettext
- dpgettext2
- environ_
getenv - file_
get_ contents - file_
open_ tmp - file_
read_ link - file_
set_ contents - file_
test - filename_
display_ basename - filename_
display_ name - filename_
from_ uri - filename_
to_ uri - find_
program_ in_ path - format_
size - format_
size_ full - get_
application_ name - get_
charset - get_
codeset - get_
current_ dir - get_
current_ time - get_
environ - get_
home_ dir - get_
host_ name - get_
language_ names - get_
locale_ variants - get_
monotonic_ time - get_
num_ processors - get_
prgname - get_
program_ name - Same as
get_prgname()
. - get_
real_ name - get_
real_ time - get_
system_ config_ dirs - get_
system_ data_ dirs - get_
tmp_ dir - get_
user_ cache_ dir - get_
user_ config_ dir - get_
user_ data_ dir - get_
user_ name - get_
user_ runtime_ dir - get_
user_ special_ dir - getenv
- hostname_
is_ ascii_ encoded - hostname_
is_ ip_ address - hostname_
is_ non_ ascii - hostname_
to_ ascii - hostname_
to_ unicode - listenv
- log_
remove_ handler - main_
current_ source - main_
depth - markup_
escape_ text - mem_
is_ system_ malloc - mem_
profile - mkdir_
with_ parents - mkdtemp
- mkdtemp_
full - mkstemp
- mkstemp_
full - on_
error_ query - on_
error_ stack_ trace - path_
get_ basename - path_
get_ dirname - path_
is_ absolute - path_
skip_ root - pattern_
match_ simple - random_
double - random_
double_ range - random_
int - random_
int_ range - random_
set_ seed - reload_
user_ special_ dirs_ cache - return_
if_ fail_ warning - rmdir
- set_
application_ name - set_
prgname - set_
program_ name - Same as
set_prgname()
. - setenv
- shell_
parse_ argv - shell_
quote - shell_
unquote - spaced_
primes_ closest - spawn_
check_ exit_ status - spawn_
command_ line_ async - stpcpy
- unlink
- unsetenv
- uri_
escape_ string - uri_
list_ extract_ uris - uri_
parse_ scheme - uri_
unescape_ segment - uri_
unescape_ string - usleep
- variant_
get_ gtype - warn_
message