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 | Flags to be passed to [ |
ByteArray | Contains the public fields of a GByteArray. |
Bytes | A shared immutable byte slice (the equivalent of |
Checksum | An opaque structure representing a checksumming operation.
To create a new GChecksum, use |
Date | |
DateTime |
|
EnumClass | Representation of an |
EnumValue | Representation of a single enum value of an |
FileSetContentsFlags | Flags to pass to |
FileTest | A test to perform on a file using |
FlagsBuilder | Builder for conveniently setting/unsetting flags and returning a |
FlagsClass | Representation of a |
FlagsValue | Representation of a single flags value of a |
FormatSizeFlags | Flags to modify the format of the string returned by |
GString | |
GlibLogger | An implementation of a |
IOCondition | A bitwise combination representing a condition to watch for on an event source. |
KeyFile | The GKeyFile struct contains only private data and should not be accessed directly. |
KeyFileFlags | Flags which influence the parsing. |
LogHandlerId | |
LogLevelFlags | Flags specifying the level of log messages. |
LogLevels | |
MainContext | The |
MainLoop | The |
OptionFlags | Flags which modify individual options. |
ParamFlags | Through the |
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 | The signal flags are used to specify a signal’s behaviour, the overall signal description outlines how especially the RUN flags control the stages of a signal emission. |
Source | The |
SourceFuture | Represents a |
SourceStream | Represents a |
SpawnFlags | Flags passed to |
String | A mutable text buffer that grows automatically. |
SyncSender | A |
ThreadPool | |
TimeZone |
|
Uri | The |
UriFlags | Flags that describe a URI. |
UriHideFlags | Flags describing what parts of the URI to hide in
|
UriParamsFlags | Flags modifying the way parameters are handled by |
ValueArray | |
VariantDict |
|
VariantIter | Iterator over items in a variant. |
VariantTy | Describes |
VariantType | Describes |
Enums
ChecksumType | The hashing algorithm to be used by |
DateMonth | Enumeration representing a month; values are |
DateWeekday | Enumeration representing a day of the week; |
FileError | |
GlibLoggerDomain | Enumeration of the possible domain handling behaviours for a
|
GlibLoggerFormat | Enumeration of the possible formatting behaviours for a
|
KeyFileError | Error codes returned by key file parsing. |
LogLevel | |
OptionArg | The |
SeekType | An enumeration specifying the base position for a
|
TimeType | Disambiguates a given time in two ways. |
UriError | v2_66 Error codes returned by |
UserDirectory | These are logical ids for special directories which are defined
depending on the platform used. You should use |
Constants
CLONE_MACRO_LOG_DOMAIN | This is the log domain used by the |
Statics
CSET_A_2_Z | The set of uppercase ASCII alphabet characters.
Used for specifying valid identifier characters
in |
CSET_DIGITS | The set of ASCII digits.
Used for specifying valid identifier characters
in |
CSET_a_2_z | The set of lowercase ASCII alphabet characters.
Used for specifying valid identifier characters
in |
KEY_FILE_DESKTOP_GROUP | The name of the main group of a desktop entry file, as defined in the Desktop Entry Specification. Consult the specification for more details about the meanings of the keys below. |
KEY_FILE_DESKTOP_KEY_ACTIONS | A key under |
KEY_FILE_DESKTOP_KEY_CATEGORIES | A key under |
KEY_FILE_DESKTOP_KEY_COMMENT | A key under |
KEY_FILE_DESKTOP_KEY_DBUS_ACTIVATABLE | A key under |
KEY_FILE_DESKTOP_KEY_EXEC | A key under |
KEY_FILE_DESKTOP_KEY_GENERIC_NAME | A key under |
KEY_FILE_DESKTOP_KEY_HIDDEN | A key under |
KEY_FILE_DESKTOP_KEY_ICON | A key under |
KEY_FILE_DESKTOP_KEY_MIME_TYPE | A key under |
KEY_FILE_DESKTOP_KEY_NAME | A key under |
KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN | A key under |
KEY_FILE_DESKTOP_KEY_NO_DISPLAY | A key under |
KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN | A key under |
KEY_FILE_DESKTOP_KEY_PATH | A key under |
KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY | A key under |
KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS | A key under |
KEY_FILE_DESKTOP_KEY_TERMINAL | A key under |
KEY_FILE_DESKTOP_KEY_TRY_EXEC | A key under |
KEY_FILE_DESKTOP_KEY_TYPE | A key under |
KEY_FILE_DESKTOP_KEY_URL | A key under |
KEY_FILE_DESKTOP_KEY_VERSION | A key under |
KEY_FILE_DESKTOP_TYPE_APPLICATION | The value of the |
KEY_FILE_DESKTOP_TYPE_DIRECTORY | The value of the |
KEY_FILE_DESKTOP_TYPE_LINK | The value of the |
OPTION_REMAINING | If a long option in the main group has this name, it is not treated as a
regular option. Instead it collects all non-option arguments which would
otherwise be left in |
STR_DELIMITERS | The standard delimiters, used in |
TEST_OPTION_ISOLATE_DIRS | v2_60 Creates a unique temporary directory for each unit test and uses
|
URI_RESERVED_CHARS_GENERIC_DELIMITERS | Generic delimiters characters as defined in
RFC 3986. Includes |
URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS | Subcomponent delimiter characters as defined in
RFC 3986. Includes |
g_param_spec_types |
Traits
ParamSpecType |
Functions
access | |
application_name | |
assert_warning | |
assertion_message | |
assertion_message_cmpstr | |
base64_decode | |
base64_encode | |
bit_nth_lsf | |
bit_nth_msf | |
bit_storage | |
build_filenamev | Behaves exactly like |
build_pathv | Behaves exactly like |
canonicalize_filename | v2_58 Gets the canonical file name from |
charset | Obtain the character set for the current locale. |
chdir | A wrapper for the POSIX |
check_version | Checks that the GLib library in use is compatible with the
given version. Generally you would pass in the constants
|
child_watch_future | Create a |
child_watch_future_with_priority | Create a |
clear_error | If |
codeset | |
compute_checksum_for_bytes | Computes the checksum for a binary |
compute_checksum_for_data | Computes the checksum for a binary |
compute_checksum_for_string | Computes the checksum of a string. |
compute_hmac_for_bytes | v2_50 Computes the HMAC for a binary |
compute_hmac_for_data | Computes the HMAC for a binary |
compute_hmac_for_string | Computes the HMAC for a string. |
console_charset | v2_62 |
current_dir | |
dcgettext | |
dgettext | |
dngettext | |
dpgettext | |
dpgettext2 | |
environ | |
environ_getenv | |
file_get_contents | |
file_open_tmp | |
file_read_link | |
file_set_contents | |
file_set_contents_full | v2_66 |
file_test | |
filename_display_basename | |
filename_display_name | |
filename_from_uri | |
filename_to_uri | |
find_program_in_path | |
format_size | |
format_size_full | |
getenv | |
home_dir | |
host_name | |
hostname_is_ascii_encoded | |
hostname_is_ip_address | |
hostname_is_non_ascii | |
hostname_to_ascii | |
hostname_to_unicode | |
interval_stream | Create a |
interval_stream_seconds | Create a |
interval_stream_seconds_with_priority | Create a |
interval_stream_with_priority | Create a |
is_canonical_pspec_name | |
language_names | |
language_names_with_category | v2_58 |
listenv | |
locale_variants | |
log_default_handler | |
log_remove_handler | |
log_set_always_fatal | |
log_set_default_handler | To set back the default print handler, use the |
log_set_fatal_mask | |
log_set_handler | |
log_unset_default_handler | To set the default print handler, use the |
main_current_source | |
main_depth | |
markup_escape_text | |
mkdir_with_parents | |
mkdtemp | |
mkdtemp_full | |
mkstemp | |
mkstemp_full | |
monotonic_time | |
num_processors | |
on_error_query | |
on_error_stack_trace | |
os_info | v2_64 |
path_get_basename | |
path_get_dirname | |
path_is_absolute | |
path_skip_root | |
pattern_match_simple | |
prgname | |
program_name | Same as |
random_double | |
random_double_range | |
random_int | |
random_int_range | |
random_set_seed | |
real_name | |
real_time | |
reload_user_special_dirs_cache | |
return_if_fail_warning | |
rmdir | |
rust_log_handler | Provides a glib log handler which routes all logging messages to the
|
set_application_name | |
set_prgname | |
set_print_handler | To set back the default print handler, use the |
set_printerr_handler | To set back the default print handler, use the |
set_program_name | Same as |
setenv | |
shell_parse_argv | Parses a command line into an argument vector, in much the same way
the shell would, but without many of the expansions the shell would
perform (variable expansion, globs, operators, filename expansion,
etc. are not supported). The results are defined to be the same as
those you would get from a UNIX98 /bin/sh, as long as the input
contains none of the unsupported shell expansions. If the input
does contain such expansions, they are passed through
literally. Possible errors are those from the |
shell_quote | Quotes a string so that the shell (/bin/sh) will interpret the
quoted string to mean |
shell_unquote | Unquotes a string as the shell (/bin/sh) would. Only handles
quotes; if a string contains file globs, arithmetic operators,
variables, backticks, redirections, or other special-to-the-shell
features, the result will be different from the result a real shell
would produce (the variables, backticks, etc. will be passed
through literally instead of being expanded). This function is
guaranteed to succeed if applied to the result of
|
spaced_primes_closest | Gets the smallest prime number from a built-in array of primes which
is larger than |
spawn_async | See |
spawn_async_with_fds | v2_58 and non-WindowsIdentical to |
spawn_async_with_pipes | Non-Windows Identical to |
spawn_check_exit_status | Set |
spawn_command_line_async | Unix A simple version of |
stpcpy | Copies a nul-terminated string into the dest buffer, include the trailing nul, and return a pointer to the trailing nul byte. This is useful for concatenating multiple strings together without having to repeatedly scan for the end. |
system_config_dirs | |
system_data_dirs | |
timeout_future | Create a |
timeout_future_seconds | Create a |
timeout_future_seconds_with_priority | Create a |
timeout_future_with_priority | Create a |
tmp_dir | |
unix_open_pipe | Similar to the UNIX |
unix_signal_future | Unix Create a |
unix_signal_future_with_priority | Unix Create a |
unix_signal_stream | Unix Create a |
unix_signal_stream_with_priority | Unix Create a |
unlink | A wrapper for the POSIX |
unset_print_handler | To set the default print handler, use the |
unset_printerr_handler | To set the default print handler, use the |
unsetenv | Removes an environment variable from the environment. |
user_cache_dir | |
user_config_dir | |
user_data_dir | |
user_name | |
user_runtime_dir | |
user_special_dir | |
usleep | Pauses the current thread for the given number of microseconds. |
uuid_string_is_valid | v2_52 Parses the string |
uuid_string_random | v2_52 Generates a random UUID (RFC 4122 version 4) as a string. It has the same
randomness guarantees as |
warn_message | Internal function used to print messages from the public |
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 |