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.80.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
gtk4::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 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 glib_sys as ffi;
pub use gobject_sys as gobject_ffi;
pub use self::source::*;
Modules§
- boxed
IMPL
Boxed wrapper implementation.- boxed_
inline IMPL
BoxedInline wrapper implementation.- char
- clone
- closure
- collections
- enums
- error
Error
binding and helper trait.- match_
info - object
IMPL
Object wrapper implementation andObject
binding.- prelude
- Traits and essential types intended for blanket imports.
- property
- regex
- This module is inefficient and should not be used by Rust programs except for compatibility with GLib.Regex based APIs.
- shared
IMPL
Shared (reference counted) wrapper implementation.- signal
IMPL
Low level signal support.- source
- subclass
- Module containing infrastructure for subclassing
GObject
s and registering boxed types. - thread_
guard - 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
Thewrapper!
macro and miscellaneous wrapper traits.
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.
- closure
- Macro for creating a
Closure
object. This is a wrapper aroundClosure::new
that automatically type checks its arguments at run-time. - closure_
local - The same as
closure!
but usesClosure::new_local
as a constructor. This is useful for closures which can’t be sent across threads. See the documentation ofclosure!
for details. - debug
log
andlog_macros
- A macro which behaves exactly as
log::debug!
except that it sets the current log target to the contents of aG_LOG_DOMAIN
constant (and fails to build if not defined). - error
log
andlog_macros
- A macro which behaves exactly as
log::error!
except that it sets the current log target to the contents of aG_LOG_DOMAIN
constant (and fails to build if not defined). - function_
name - This macro returns the name of the enclosing function.
As the internal implementation is based on the
std::any::type_name
, this macro derives all the limitations of this function. - 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.
- gformat
- Creates a
GString
using interpolation of runtime expressions. - glib_
boxed_ inline_ wrapper - Wrapper implementations for BoxedInline types. See
wrapper!
. - glib_
boxed_ wrapper - Wrapper implementations for Boxed types. See
wrapper!
. - glib_
object_ wrapper - ObjectType implementations for Object types. See
wrapper!
. - glib_
shared_ wrapper - Wrapper implementations for shared types. See
wrapper!
. - gstr
- Converts a static string literal into a static nul-terminated string.
- info
log
andlog_macros
- A macro which behaves exactly as
log::info!
except that it sets the current log target to the contents of aG_LOG_DOMAIN
constant (and fails to build if not defined). - log_
structured - Macro used to log using GLib structured logging system.
- result_
from_ gboolean - trace
log
andlog_macros
- A macro which behaves exactly as
log::trace!
except that it sets the current log target to the contents of aG_LOG_DOMAIN
constant (and fails to build if not defined). - warn
log
andlog_macros
- A macro which behaves exactly as
log::warn!
except that it sets the current log target to the contents of aG_LOG_DOMAIN
constant (and fails to build if not defined). - wrapper
- Defines a wrapper type and implements the appropriate traits.
Structs§
- Binding
GObject
instance (or source) and another property on anotherGObject
instance (or target).- Binding
Flags - Flags to be passed to
ObjectExt::bind_property()
or [ObjectExt::bind_property_full()
][crate::prelude::ObjectExt::bind_property_full()]. - Binding
Group v2_72
GBindingGroup
can be used to bind multiple properties from an object collectively.- Binding
Group Builder v2_72
- Builder for binding group bindings.
- Boxed
AnyObject - This is a subclass of
glib::object::Object
capable of storing any Rust type. It let’s you insert a Rust type anywhere aglib::object::Object
is needed. The inserted value can then be borrowed as a Rust type, by using the various provided methods. - Byte
Array - Contains the public fields of a GByteArray.
- Bytes
- A shared immutable byte slice (the equivalent of
Rc<[u8]>
). - Checksum
- GLib provides a generic API for computing checksums (or ‘digests’) for a sequence of arbitrary bytes, using various hashing algorithms like MD5, SHA-1 and SHA-256. Checksums are commonly used in various environments and specifications.
- Collation
Key - A
CollationKey
allows ordering strings using the linguistically correct rules for the current locale. - Date
- GLib type: Inline allocated boxed type with stack copy semantics.
- Date
Time GDateTime
is a structure that combines a Gregorian date and time into a single structure.- Exit
Code - File
SetContents Flags v2_66
- Flags to pass to g_file_set_contents_full() to affect its safety and performance.
- Filename
Collation Key - A
FilenameCollationKey
allows 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. - Format
Size Flags - Flags to modify the format of the string returned by g_format_size_full().
- Future
With Timeout Error - The error returned when a future times out.
- GStr
- Representation of a borrowed
GString
. - GStr
Interior NulError - Error type indicating that a buffer had unexpected nul-bytes.
- GString
- A type representing an owned, C-compatible, nul-terminated UTF-8 string.
- GString
Builder - A mutable text buffer that grows automatically.
- GString
Interior NulError - Error type indicating that a buffer had unexpected nul-bytes.
- GString
NoTrailing NulError - Error type indicating that a buffer did not have a trailing nul-byte.
- GString
Ptr NULL
-terminated UTF-8 string as stored inStrV
.- GString
Utf8 Error - Error type indicating that a buffer had invalid UTF-8.
- Glib
Logger log
- An implementation of a
log
compatible logger which logs over glib logging facilities. - IConv
- The GIConv struct wraps an iconv() conversion descriptor. It contains private data and should only be accessed using the following functions.
- IOCondition
- A bitwise combination representing a condition to watch for on an event source.
- Interface
Info - A structure that provides information to the type system which is used specifically for managing interface types.
- Join
Error - Task failure from awaiting a
JoinHandle
. - Join
Handle - A handle to a task running on a
MainContext
. - KeyFile
GKeyFile
parses .ini-like config files.- KeyFile
Flags - Flags which influence the parsing.
- LogField
- Structure representing a single field in a structured log entry.
- LogHandler
Id - LogLevel
Flags - Flags specifying the level of log messages.
- LogLevels
- Main
Context - The
GMainContext
struct is an opaque data type representing a set of sources to be handled in a main loop. - Main
Context Acquire Guard - Main
Context Flags v2_72
- Flags to pass to
GLib::MainContext::new_with_flags()
which affect the behaviour of aMainContext
. - Main
Loop - The
GMainLoop
struct is an opaque data type representing the main event loop of a GLib or GTK application. - Markup
Parse Context - A parse context is used to parse a stream of bytes that you expect to contain marked-up text.
- Option
Flags - Flags which modify individual options.
- Param
Flags - Through the
ParamFlags
flag values, certain aspects of parameters can be configured. - Param
Spec GParamSpec
encapsulates the metadata required to specify parameters, such asGObject
properties.- Param
Spec Boolean - GLib type: Shared boxed type with reference counted clone semantics.
- Param
Spec Boolean Builder - Param
Spec Boxed - A
ParamSpec
derived structure that contains the meta data for boxed properties. - Param
Spec Boxed Builder - Param
Spec Char - GLib type: Shared boxed type with reference counted clone semantics.
- Param
Spec Char Builder - Param
Spec Double - A
ParamSpec
derived structure that contains the meta data for double properties. - Param
Spec Double Builder - Param
Spec Enum - GLib type: Shared boxed type with reference counted clone semantics.
- Param
Spec Enum Builder - Param
Spec Flags - GLib type: Shared boxed type with reference counted clone semantics.
- Param
Spec Flags Builder - Param
Spec Float - A
ParamSpec
derived structure that contains the meta data for float properties. - Param
Spec Float Builder - Param
SpecG Type - A
ParamSpec
derived structure that contains the meta data forGType
properties. - Param
SpecG Type Builder - Param
Spec Int - GLib type: Shared boxed type with reference counted clone semantics.
- Param
Spec Int64 - GLib type: Shared boxed type with reference counted clone semantics.
- Param
Spec Int64 Builder - Param
Spec IntBuilder - Param
Spec Long - GLib type: Shared boxed type with reference counted clone semantics.
- Param
Spec Long Builder - Param
Spec Object - A
ParamSpec
derived structure that contains the meta data for object properties. - Param
Spec Object Builder - Param
Spec Override - A
ParamSpec
derived structure that redirects operations to other types ofParamSpec
. - Param
Spec Override Builder - Param
Spec Param - A
ParamSpec
derived structure that contains the meta data forG_TYPE_PARAM
properties. - Param
Spec Param Builder - Param
Spec Pointer - A
ParamSpec
derived structure that contains the meta data for pointer properties. - Param
Spec Pointer Builder - Param
Spec String - A
ParamSpec
derived structure that contains the meta data for string properties. - Param
Spec String Builder - Param
SpecU Char - GLib type: Shared boxed type with reference counted clone semantics.
- Param
SpecU Char Builder - Param
SpecU Int - GLib type: Shared boxed type with reference counted clone semantics.
- Param
SpecU Int64 - GLib type: Shared boxed type with reference counted clone semantics.
- Param
SpecU Int64 Builder - Param
SpecU IntBuilder - Param
SpecU Long - GLib type: Shared boxed type with reference counted clone semantics.
- Param
SpecU Long Builder - Param
Spec Unichar - GLib type: Shared boxed type with reference counted clone semantics.
- Param
Spec Unichar Builder - Param
Spec Value Array - A
ParamSpec
derived structure that contains the meta data forGValueArray
properties. - Param
Spec Value Array Builder - Param
Spec Variant - A
ParamSpec
derived structure that contains the meta data forGVariant
properties. - Param
Spec Variant Builder - Quark
- Regex
- A
GRegex
is the “compiled” form of a regular expression pattern. - Regex
Compile Flags - Flags specifying compile-time options.
- Regex
Match Flags - Flags specifying match-time options.
- Signal
Flags - The signal flags are used to specify a signal’s behaviour.
- Signal
Group v2_74
GSignalGroup
manages a collection of signals on aGObject
.- Source
- The
GSource
struct is an opaque data type representing an event source. - Source
Future - Represents a
Future
around aglib::Source
. The future will be resolved once the source has provided a value - Source
Stream - Represents a
Stream
around aglib::Source
. The stream will be provide all values that are provided by the source - Spawn
Flags - Flags passed to g_spawn_sync(), g_spawn_async() and g_spawn_async_with_pipes().
- Spawn
Within Join Handle - Variant of
JoinHandle
that is returned fromMainContext::spawn_from_within
. - Thread
Handle - A handle to a thread running on a
ThreadPool
. - Thread
Pool - The
GThreadPool
struct represents a thread pool. - Time
Span - A value representing an interval of time, in microseconds.
- Time
Zone - A
GTimeZone
represents a time zone, at no particular point in time. - Type
Flags - Bit masks used to check or determine characteristics of a type.
- Type
Info - This structure is used to provide the type system with the information required to initialize and destruct (finalize) a type’s class and its instances.
- Type
Module GTypeModule
provides a simple implementation of theGTypePlugin
interface.- Type
Plugin - An interface that handles the lifecycle of dynamically loaded types.
- Type
Value Table 'i'
: Integers, passed ascollect_values[].v_int
'l'
: Longs, passed ascollect_values[].v_long
'd'
: Doubles, passed ascollect_values[].v_double
'p'
: Pointers, passed ascollect_values[].v_pointer
- Uri
v2_66
- The
GUri
type and related functions can be used to parse URIs into their components, and build valid URIs from individual components. - UriFlags
v2_66
- Flags that describe a URI.
- UriHide
Flags v2_66
- Flags describing what parts of the URI to hide in
g_uri_to_string_partial(). Note that
PASSWORD
andAUTH_PARAMS
will only work if the #GUri was parsed with the corresponding flags. - UriParams
Flags v2_66
- Flags modifying the way parameters are handled by g_uri_parse_params() and #GUriParamsIter.
- Value
Array - GLib type: Boxed type with copy-on-clone semantics.
- Variant
Dict VariantDict
is a mutable key/value store where the keys are always strings and the values areVariant
s.- Variant
Iter - Iterator over items in a variant.
- Variant
StrIter - Iterator over items in a variant of type
as
. - Variant
Ty - Describes
Variant
types. - Variant
TyIterator - An iterator over the individual components of a tuple VariantTy.
- Variant
Type - Describes
Variant
types.
Enums§
- Character
Decomposition - The result of a single step of the Unicode canonical decomposition algorithm
- Checksum
Type - The hashing algorithm to be used by #GChecksum when performing the digest of some data.
- Control
Flow - Continue calling the closure in the future iterations or drop it.
- Convert
Error - Error codes returned by character set conversion routines.
- CvtError
- A wrapper for
ConvertError
that can hold an offset into the input string. - Date
Month - Enumeration representing a month; values are
January
,February
, etc.BadMonth
is the invalid value. - Date
Weekday - Enumeration representing a day of the week;
Monday
,Tuesday
, etc.BadWeekday
is an invalid weekday. - Decomposition
Kind - The kind of decomposition to perform
- File
Error - Values corresponding to @errno codes returned from file operations on UNIX. Unlike @errno codes, GFileError values are available on all systems, even Windows. The exact meaning of each code depends on what sort of file operation you were performing; the UNIX documentation gives more details. The following error code descriptions come from the GNU C Library manual, and are under the copyright of that manual.
- GStr
Error - Error type holding all possible failures when creating a
GStr
reference. - GString
From Error - Error type holding all possible failures when creating a
GString
. - Glib
Logger Domain log
- Enumeration of the possible domain handling behaviours for a
GlibLogger
. - Glib
Logger Format log
- Enumeration of the possible formatting behaviours for a
GlibLogger
. - IConv
Error - A wrapper for
std::io::Error
that can hold an offset into an input string. - KeyFile
Error - Error codes returned by key file parsing.
- LogLevel
- LogWriter
Output - Return values from #GLogWriterFuncs to indicate whether the given log entry was successfully handled by the writer, or whether there was an error in handling it (and hence a fallback writer should be used).
- Markup
Error - Error codes returned by markup parsing.
- Normalize
Mode - Defines how a Unicode string is transformed in a canonical form, standardizing such issues as whether a character with an accent is represented as a base character and combining accent or as a single precomposed character. Unicode strings should generally be normalized before comparing them.
- Option
Arg - The #GOptionArg enum values determine which type of extra argument the
options expect to find. If an option expects an extra argument, it can
be specified in several ways; with a short option:
-x arg
, with a long option:--name arg
or combined in a single argument:--name=arg
. - Seek
Type - An enumeration specifying the base position for a g_io_channel_seek_position() operation.
- Time
Type - Disambiguates a given time in two ways.
- Unicode
Break Type - These are the possible line break classifications.
- Unicode
Script - The #GUnicodeScript enumeration identifies different writing systems. The values correspond to the names as defined in the Unicode standard. The enumeration has been added in GLib 2.14, and is interchangeable with #PangoScript.
- Unicode
Type - These are the possible character classifications from the Unicode specification. See Unicode Character Database.
- UriError
v2_66
- Error codes returned by #GUri methods.
- Variant
Class - The range of possible top-level types of #GVariant instances.
Constants§
- CLONE_
MACRO_ LOG_ DOMAIN - This is the log domain used by the
clone!
macro. If you want to use a custom logger (it prints to stdout by default), you can set your own logger using the correspondinglog
functions. - NONE_
STR
Statics§
- CSET_
A_ 2_ Z - The set of uppercase ASCII alphabet characters. Used for specifying valid identifier characters in #GScannerConfig.
- CSET_
DIGITS - The set of ASCII digits. Used for specifying valid identifier characters in #GScannerConfig.
- CSET_
a_ 2_ z - The set of lowercase ASCII alphabet characters. Used for specifying valid identifier characters in #GScannerConfig.
- KEY_
FILE_ DESKTOP_ GROUP - The name of the main group of a desktop entry file, as defined in the Desktop Entry Specification.
- KEY_
FILE_ DESKTOP_ KEY_ ACTIONS - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a string list giving the available application actions. - KEY_
FILE_ DESKTOP_ KEY_ CATEGORIES - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a list of strings giving the categories in which the desktop entry should be shown in a menu. - KEY_
FILE_ DESKTOP_ KEY_ COMMENT - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a localized string giving the tooltip for the desktop entry. - KEY_
FILE_ DESKTOP_ KEY_ DBUS_ ACTIVATABLE - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a boolean set to true if the application is D-Bus activatable. - KEY_
FILE_ DESKTOP_ KEY_ EXEC - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a string giving the command line to execute. - KEY_
FILE_ DESKTOP_ KEY_ GENERIC_ NAME - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a localized string giving the generic name of the desktop entry. - KEY_
FILE_ DESKTOP_ KEY_ HIDDEN - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a boolean stating whether the desktop entry has been deleted by the user. - KEY_
FILE_ DESKTOP_ KEY_ ICON - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a localized string giving the name of the icon to be displayed for the desktop entry. - KEY_
FILE_ DESKTOP_ KEY_ MIME_ TYPE - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a list of strings giving the MIME types supported by this desktop entry. - KEY_
FILE_ DESKTOP_ KEY_ NAME - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a localized string giving the specific name of the desktop entry. - KEY_
FILE_ DESKTOP_ KEY_ NOT_ SHOW_ IN - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a list of strings identifying the environments that should not display the desktop entry. - KEY_
FILE_ DESKTOP_ KEY_ NO_ DISPLAY - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a boolean stating whether the desktop entry should be shown in menus. - KEY_
FILE_ DESKTOP_ KEY_ ONLY_ SHOW_ IN - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a list of strings identifying the environments that should display the desktop entry. - KEY_
FILE_ DESKTOP_ KEY_ PATH - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a string containing the working directory to run the program in. - KEY_
FILE_ DESKTOP_ KEY_ STARTUP_ NOTIFY - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a boolean stating whether the application supports the Startup Notification Protocol Specification. - KEY_
FILE_ DESKTOP_ KEY_ STARTUP_ WM_ CLASS - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is string identifying the WM class or name hint of a window that the application will create, which can be used to emulate Startup Notification with older applications. - KEY_
FILE_ DESKTOP_ KEY_ TERMINAL - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a boolean stating whether the program should be run in a terminal window. - KEY_
FILE_ DESKTOP_ KEY_ TRY_ EXEC - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a string giving the file name of a binary on disk used to determine if the program is actually installed. - KEY_
FILE_ DESKTOP_ KEY_ TYPE - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a string giving the type of the desktop entry. - KEY_
FILE_ DESKTOP_ KEY_ URL - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a string giving the URL to access. - KEY_
FILE_ DESKTOP_ KEY_ VERSION - A key under
GLib::KEY_FILE_DESKTOP_GROUP
, whose value is a string giving the version of the Desktop Entry Specification used for the desktop entry file. - KEY_
FILE_ DESKTOP_ TYPE_ APPLICATION - The value of the
GLib::KEY_FILE_DESKTOP_KEY_TYPE
, key for desktop entries representing applications. - KEY_
FILE_ DESKTOP_ TYPE_ DIRECTORY - The value of the
GLib::KEY_FILE_DESKTOP_KEY_TYPE
, key for desktop entries representing directories. - KEY_
FILE_ DESKTOP_ TYPE_ LINK - The value of the
GLib::KEY_FILE_DESKTOP_KEY_TYPE
, key for desktop entries representing links to documents. - 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
argv
. The option must be of typeOptionArg::Callback
,OptionArg::StringArray
orOptionArg::FilenameArray
. - STR_
DELIMITERS - The standard delimiters, used in
strdelimit()
. - TEST_
OPTION_ ISOLATE_ DIRS v2_60
- A value that can be passed as an option to
test_init()
. - TEST_
OPTION_ NONFATAL_ ASSERTIONS v2_84
- A value that can be passed as an option to
test_init()
. - TEST_
OPTION_ NO_ PRGNAME v2_84
- A value that can be passed as an option to
test_init()
. - 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
!$&'()*+,;=
.
Traits§
- HasParam
Spec - IntoG
Str - A trait to accept both
&str
or&GStr
as an argument. - Into
OptionalG Str - A trait to accept both
Option<&str>
orOption<&GStr>
as an argument. - Param
Spec Builder Ext - A trait implemented by the various
ParamSpec
builder types. - Param
Spec Type - Unichar
- This trait provides access to Unicode character classification and manipulations functions provided by GLib that do not exist in the standard library
Functions§
- access
- A wrapper for the POSIX access() function. This function is used to test a pathname for one or several of read, write or execute permissions, or just existence.
- application_
name - Gets a human-readable name for the application, as set by
g_set_application_name(). This name should be localized if
possible, and is intended for display to the user. Contrast with
g_get_prgname(), which gets a non-localized name. If
g_set_application_name() has not been called, returns the result of
g_get_prgname() (which may be
None
if g_set_prgname() has also not been called). - base64_
decode - Decode a sequence of Base-64 encoded text into binary data. Note that the returned binary data is not necessarily zero-terminated, so it should not be used as a character string.
- base64_
encode - Encode a sequence of binary data into its Base-64 stringified representation.
- casefold
- charset
- Obtain the character set for the current locale.
- check_
version - Checks that the GLib library in use is compatible with the given version.
- child_
watch_ future - Create a
Future
that will resolve once the child process with the given pid exits - child_
watch_ future_ with_ priority - Create a
Future
that will resolve once the child process with the given pid exits - codeset
- Gets the character set for the current locale.
- compute_
checksum_ for_ bytes - Computes the checksum for a binary @data. This is a convenience wrapper for g_checksum_new(), g_checksum_get_string() and g_checksum_free().
- compute_
checksum_ for_ data - Computes the checksum for a binary @data of @length. This is a convenience wrapper for g_checksum_new(), g_checksum_get_string() and g_checksum_free().
- compute_
checksum_ for_ string - compute_
hmac_ for_ bytes - Computes the HMAC for a binary @data. This is a convenience wrapper for g_hmac_new(), g_hmac_get_string() and g_hmac_unref().
- compute_
hmac_ for_ data - Computes the HMAC for a binary @data of @length. This is a convenience wrapper for g_hmac_new(), g_hmac_get_string() and g_hmac_unref().
- console_
charset v2_62
- Obtains the character set used by the console attached to the process, which is suitable for printing output to the terminal.
- convert
- Converts a string from one character set to another.
- convert_
with_ fallback - Converts a string from one character set to another, possibly including fallback sequences for characters not representable in the output. Note that it is not guaranteed that the specification for the fallback sequences in @fallback will be honored. Some systems may do an approximate conversion from @from_codeset to @to_codeset in their iconv() functions, in which case GLib will simply return that approximate conversion.
- current_
dir - Gets the current directory.
- dcgettext
- This is a variant of g_dgettext() that allows specifying a locale
category instead of always using
LC_MESSAGES
. See g_dgettext() for more information about how this functions differs from calling dcgettext() directly. - dgettext
- This function is a wrapper of dgettext() which does not translate the message if the default domain as set with textdomain() has no translations for the current locale.
- dngettext
- This function is a wrapper of dngettext() which does not translate the message if the default domain as set with textdomain() has no translations for the current locale.
- dpgettext
- This function is a variant of g_dgettext() which supports a disambiguating message context. GNU gettext uses the ‘\004’ character to separate the message context and message id in @msgctxtid. If 0 is passed as @msgidoffset, this function will fall back to trying to use the deprecated convention of using “|” as a separation character.
- dpgettext2
- This function is a variant of g_dgettext() which supports a disambiguating message context. GNU gettext uses the ‘\004’ character to separate the message context and message id in @msgctxtid.
- environ
- Gets the list of environment variables for the current process.
- environ_
getenv - file_
get_ contents - Reads an entire file into allocated memory, with good error checking.
- file_
open_ tmp - Opens a file for writing in the preferred directory for temporary files (as returned by g_get_tmp_dir()).
- file_
set_ contents - Writes all of @contents to a file named @filename. This is a convenience
wrapper around calling g_file_set_contents_full() with
flags
set toG_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING
andmode
set to0666
. - file_
set_ contents_ full v2_66
- Writes all of @contents to a file named @filename, with good error checking. If a file called @filename already exists it will be overwritten.
- filename_
charsets - Determines the preferred character sets used for filenames. The first character set from the @charsets is the filename encoding, the subsequent character sets are used when trying to generate a displayable representation of a filename, see g_filename_display_name().
- filename_
display_ basename - Returns the display basename for the particular filename, guaranteed to be valid UTF-8. The display name might not be identical to the filename, for instance there might be problems converting it to UTF-8, and some files can be translated in the display.
- filename_
display_ name - Converts a filename into a valid UTF-8 string. The conversion is
not necessarily reversible, so you should keep the original around
and use the return value of this function only for display purposes.
Unlike g_filename_to_utf8(), the result is guaranteed to be non-
None
even if the filename actually isn’t in the GLib file name encoding. - filename_
from_ uri - Converts an escaped ASCII-encoded URI to a local filename in the encoding used for filenames.
- filename_
from_ utf8 - Converts a string from UTF-8 to the encoding GLib uses for filenames. Note that on Windows GLib uses UTF-8 for filenames; on other platforms, this function indirectly depends on the current locale.
- filename_
to_ uri - Converts an absolute filename to an escaped ASCII-encoded URI, with the path component following Section 3.3. of RFC 2396.
- filename_
to_ utf8 - Converts a string which is in the encoding used by GLib for filenames into a UTF-8 string. Note that on Windows GLib uses UTF-8 for filenames; on other platforms, this function indirectly depends on the current locale.
- find_
program_ in_ path - Locates the first executable named @program in the user’s path, in the
same way that execvp() would locate it. Returns an allocated string
with the absolute path name, or
None
if the program is not found in the path. If @program is already an absolute path, returns a copy of @program if @program exists and is executable, andNone
otherwise. - format_
size - Formats a size (for example the size of a file) into a human readable string. Sizes are rounded to the nearest size prefix (kB, MB, GB) and are displayed rounded to the nearest tenth. E.g. the file size 3292528 bytes will be converted into the string “3.2 MB”. The returned string is UTF-8, and may use a non-breaking space to separate the number and units, to ensure they aren’t separated when line wrapped.
- format_
size_ full - Formats a size.
- future_
with_ timeout - Add a timeout to a
Future
. - future_
with_ timeout_ with_ priority - Add a timeout to a
Future
. - getenv
- Returns the value of an environment variable.
- home_
dir - Gets the current user’s home directory.
- host_
name - Return a name for the machine.
- hostname_
is_ ascii_ encoded - Tests if @hostname contains segments with an ASCII-compatible
encoding of an Internationalized Domain Name. If this returns
true
, you should decode the hostname with g_hostname_to_unicode() before displaying it to the user. - hostname_
is_ ip_ address - Tests if @hostname is the string form of an IPv4 or IPv6 address. (Eg, “192.168.0.1”.)
- hostname_
is_ non_ ascii - Tests if @hostname contains Unicode characters. If this returns
true
, you need to encode the hostname with g_hostname_to_ascii() before using it in non-IDN-aware contexts. - hostname_
to_ ascii - Converts @hostname to its canonical ASCII form; an ASCII-only string containing no uppercase letters and not ending with a trailing dot.
- hostname_
to_ unicode - Converts @hostname to its canonical presentation form; a UTF-8 string in Unicode normalization form C, containing no uppercase letters, no forbidden characters, and no ASCII-encoded segments, and not ending with a trailing dot.
- interval_
stream - Create a
Stream
that will provide a value every given number of milliseconds. - interval_
stream_ seconds - Create a
Stream
that will provide a value every given number of seconds. - interval_
stream_ seconds_ with_ priority - Create a
Stream
that will provide a value every given number of seconds. - interval_
stream_ with_ priority - Create a
Stream
that will provide a value every given number of milliseconds. - is_
canonical_ pspec_ name - language_
names - Computes a list of applicable locale names, which can be used to e.g. construct locale-dependent filenames or search paths. The returned list is sorted from most desirable to least desirable and always contains the default locale “C”.
- language_
names_ with_ category v2_58
- Computes a list of applicable locale names with a locale category name, which can be used to construct the fallback locale-dependent filenames or search paths. The returned list is sorted from most desirable to least desirable and always contains the default locale “C”.
- listenv
- Gets the names of all variables set in the environment.
- locale_
from_ utf8 - Converts a string from UTF-8 to the encoding used for strings by the C runtime (usually the same as that used by the operating system) in the current locale. On Windows this means the system codepage.
- locale_
to_ utf8 - Converts a string which is in the encoding used for strings by the C runtime (usually the same as that used by the operating system) in the current locale into a UTF-8 string.
- locale_
variants - Returns a list of derived variants of @locale, which can be used to
e.g. construct locale-dependent filenames or search paths. The returned
list is sorted from most desirable to least desirable.
This function handles territory, charset and extra locale modifiers. See
setlocale(3)
for information about locales and their format. - log_
default_ handler - log_
remove_ handler - log_
set_ always_ fatal - log_
set_ default_ handler - To set back the default print handler, use the
log_unset_default_handler
function. - log_
set_ fatal_ mask - log_
set_ handler - log_
set_ writer_ func - log_
structured_ array - log_
unset_ default_ handler - To set the default print handler, use the
log_set_default_handler
function. - log_
variant - log_
writer_ default - log_
writer_ ⚠default_ set_ use_ stderr - Sets whether GLib log functions output to stderr or stdout.
- log_
writer_ default_ would_ drop - log_
writer_ format_ fields - log_
writer_ is_ journald - log_
writer_ journald - log_
writer_ standard_ streams - log_
writer_ supports_ color - main_
current_ source - Returns the currently firing source for this thread.
- main_
depth - Returns the depth of the stack of calls to
MainContext::dispatch()
on any #GMainContext in the current thread. That is, when called from the toplevel, it gives 0. When called from within a callback fromMainContext::iteration()
(orMainLoop::run()
, etc.) it returns 1. When called from within a callback to a recursive call toMainContext::iteration()
, it returns 2. And so forth. - markup_
escape_ text - Escapes text so that the markup parser will parse it verbatim. Less than, greater than, ampersand, etc. are replaced with the corresponding entities. This function would typically be used when writing out a file to be parsed with the markup parser.
- mkdir_
with_ parents - Create a directory if it doesn’t already exist. Create intermediate parent directories as needed, too.
- mkdtemp
- Creates a temporary directory. See the mkdtemp() documentation on most UNIX-like systems.
- mkdtemp_
full - Creates a temporary directory. See the mkdtemp() documentation on most UNIX-like systems.
- mkstemp
- Opens a temporary file. See the mkstemp() documentation on most UNIX-like systems.
- mkstemp_
full - Opens a temporary file. See the mkstemp() documentation on most UNIX-like systems.
- monotonic_
time - Queries the system monotonic time.
- normalize
- num_
processors - Determine the approximate number of threads that the system will schedule simultaneously for this process. This is intended to be used as a parameter to g_thread_pool_new() for CPU bound tasks and similar cases.
- on_
error_ query - Prompts the user with
[E]xit, [H]alt, show [S]tack trace or [P]roceed
. This function is intended to be used for debugging use only. The following example shows how it can be used together with the g_log() functions. - on_
error_ stack_ trace - Invokes gdb, which attaches to the current process and shows a stack trace. Called by g_on_error_query() when the “[S]tack trace” option is selected. You can get the current process’s program name with g_get_prgname(), assuming that you have called gtk_init() or gdk_init().
- os_info
v2_64
- Get information about the operating system.
- prgname
- program_
name - Same as
get_prgname()
. - random_
double - Returns a random #gdouble equally distributed over the range [0..1).
- random_
double_ range - Returns a random #gdouble equally distributed over the range [@begin..@end).
- random_
int - Return a random #guint32 equally distributed over the range [0..2^32-1].
- random_
int_ range - Returns a random #gint32 equally distributed over the range [@begin..@end-1].
- random_
set_ seed - Sets the seed for the global random number generator, which is used by the g_random_* functions, to @seed.
- real_
name - Gets the real name of the user. This usually comes from the user’s
entry in the
passwd
file. The encoding of the returned string is system-defined. (On Windows, it is, however, always UTF-8.) If the real user name cannot be determined, the string “Unknown” is returned. - real_
time - Queries the system wall-clock time.
- reload_
user_ special_ dirs_ cache - Resets the cache used for g_get_user_special_dir(), so that the latest on-disk version is used. Call this only if you just changed the data on disk yourself.
- rust_
log_ handler log
- Provides a glib log handler which routes all logging messages to the
log crate
. - set_
application_ name - Sets a human-readable name for the application. This name should be localized if possible, and is intended for display to the user. Contrast with g_set_prgname(), which sets a non-localized name. g_set_prgname() will be called automatically by gtk_init(), but g_set_application_name() will not.
- set_
prgname - set_
print_ handler - To set back the default print handler, use the
unset_print_handler
function. - set_
printerr_ handler - To set back the default print handler, use the
unset_printerr_handler
function. - set_
program_ name - Same as
set_prgname()
. - setenv
- Sets an environment variable. On UNIX, both the variable’s name and value can be arbitrary byte strings, except that the variable’s name cannot contain ‘=’. On Windows, they should be in UTF-8.
- 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).
- shell_
quote - Quotes a string so that the shell (/bin/sh) will interpret the quoted string to mean @unquoted_string.
- shell_
unquote - Unquotes a string as the shell (/bin/sh) would.
- spaced_
primes_ closest - Gets the smallest prime number from a built-in array of primes which is larger than @num. This is used within GLib to calculate the optimum size of a #GHashTable.
- spawn_
async - Executes a child program asynchronously.
- spawn_
async_ with_ fds v2_58
and non-Windows - spawn_
async_ with_ pipes Non-Windows - spawn_
check_ exit_ status Deprecated - An old name for g_spawn_check_wait_status(), deprecated because its name is misleading.
- spawn_
check_ wait_ status v2_70
- Set @error if @wait_status indicates the child exited abnormally (e.g. with a nonzero exit code, or via a fatal signal).
- spawn_
command_ line_ async Unix - A simple version of g_spawn_async() that parses a command line with g_shell_parse_argv() and passes it to g_spawn_async().
- spawn_
future - Spawn a new infallible
Future
on the thread-default main context. - spawn_
future_ local - Spawn a new infallible
Future
on the thread-default main context. - system_
config_ dirs - Returns an ordered list of base directories in which to access system-wide configuration information.
- system_
data_ dirs - Returns an ordered list of base directories in which to access system-wide application data.
- timeout_
future - Create a
Future
that will resolve after the given number of milliseconds. - timeout_
future_ seconds - Create a
Future
that will resolve after the given number of seconds. - timeout_
future_ seconds_ with_ priority - Create a
Future
that will resolve after the given number of seconds. - timeout_
future_ with_ priority - Create a
Future
that will resolve after the given number of milliseconds. - tmp_dir
- Gets the directory to use for temporary files.
- unix_
open_ pipe - Similar to the UNIX pipe() call, but on modern systems like Linux uses the pipe2() system call, which atomically creates a pipe with the configured flags.
- unix_
signal_ future Unix - Create a
Future
that will resolve once the given UNIX signal is raised - unix_
signal_ future_ with_ priority Unix - Create a
Future
that will resolve once the given UNIX signal is raised - unix_
signal_ stream Unix - Create a
Stream
that will provide a value whenever the given UNIX signal is raised - unix_
signal_ stream_ with_ priority Unix - Create a
Stream
that will provide a value whenever the given UNIX signal is raised - unlink
- A wrapper for the POSIX unlink() function. The unlink() function deletes a name from the filesystem. If this was the last link to the file and no processes have it opened, the diskspace occupied by the file is freed.
- unset_
print_ handler - To set the default print handler, use the
set_print_handler
function. - unset_
printerr_ handler - To set the default print handler, use the
set_printerr_handler
function. - unsetenv
- Removes an environment variable from the environment.
- uri_
escape_ string - uri_
parse_ scheme - uri_
unescape_ segment - uri_
unescape_ string - user_
cache_ dir - Returns a base directory in which to store non-essential, cached data specific to particular user.
- user_
config_ dir - Returns a base directory in which to store user-specific application configuration information such as user preferences and settings.
- user_
data_ dir - Returns a base directory in which to access application data such as icons that is customized for a particular user.
- user_
name - Gets the user name of the current user. The encoding of the returned string is system-defined. On UNIX, it might be the preferred file name encoding, or something else, and there is no guarantee that it is even consistent on a machine. On Windows, it is always UTF-8.
- user_
runtime_ dir - Returns a directory that is unique to the current user on the local system.
- user_
special_ dir - Returns the full path of a special directory using its logical id.
- user_
state_ dir v2_72
- Returns a base directory in which to store state files specific to particular user.
- usleep
- Pauses the current thread for the given number of microseconds.
- utf8_
to_ utf32 - utf32_
to_ utf8 - uuid_
string_ is_ valid - Parses the string @str and verify if it is a UUID.
- uuid_
string_ random - Generates a random UUID (RFC 4122 version 4) as a string. It has the same randomness guarantees as #GRand, so must not be used for cryptographic purposes such as key generation, nonces, salts or one-time pads.
Type Aliases§
Attribute Macros§
- async_
test - An attribute macro for writing asynchronous test functions.
- derived_
properties - When applied to
ObjectImpl
- flags
- Attribute macro for defining flags using the
bitflags
crate. This macro will also define aGFlags::type_
function and theglib::Value
traits. - object_
interface - Macro for boilerplate of
ObjectInterface
implementations. - object_
subclass - Macro for boilerplate of
ObjectSubclass
implementations.
Derive Macros§
- Boxed
- Derive macro for defining a
BoxedType
::type_
function and theglib::Value
traits. Optionally, the type can be marked asnullable
to get an implementation ofglib::value::ToValueOptional
. - Downgrade
- Macro for deriving implementations of
glib::clone::Downgrade
andglib::clone::Upgrade
traits and a weak type. - Enum
- Derive macro to register a Rust enum in the GLib type system and derive the
glib::Value
traits. - Error
Domain - Derive macro for defining a GLib error domain and its associated
ErrorDomain
trait. - Properties
- This macro enables you to derive object properties in a quick way.
- Shared
Boxed - Derive macro for defining a
SharedType
::get_type
function and theglib::Value
traits. Optionally, the type can be marked asnullable
to get an implementation ofglib::value::ToValueOptional
. - Value
Delegate - Example
- Variant
- Derive macro for serializing/deserializing custom structs/enums as
glib::Variant
s.