Crate glib[][src]

glib, gobject and gio bindings for Rust

This library contains

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.

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 extern crate futures;
pub use closure::Closure;
pub use error::Error;
pub use error::BoolError;
pub use object::Cast;
pub use object::IsA;
pub use object::Object;
pub use object::ObjectExt;
pub use object::WeakRef;
pub use object::SendWeakRef;
pub use signal::SignalHandlerId;
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 types::StaticType;
pub use types::Type;
pub use value::ToValue;
pub use value::ToSendValue;
pub use value::TypedValue;
pub use value::SendValue;
pub use value::Value;
pub use value::AnyValue;
pub use value::AnySendValue;
pub use variant::StaticVariantType;
pub use variant::ToVariant;
pub use variant::Variant;
pub use char::*;
pub use source::*;
pub use send_unique::SendUniqueCell;
pub use send_unique::SendUnique;

Modules

auto
boxed

IMPL Boxed wrapper implementation.

char
closure
error

Error binding and helper trait.

functions
object

IMPL Object wrapper implementation and Object 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 The glib_wrapper! macro and miscellaneous wrapper traits.

Macros

glib_boxed_wrapper

Wrapper implementations for Boxed types. See glib_wrapper!.

glib_object_wrapper

Wrapper implementations for Object types. See glib_wrapper!.

glib_shared_wrapper

Wrapper implementations for shared types. See glib_wrapper!.

glib_wrapper

Defines a wrapper type and implements the appropriate traits.

Structs

Binding
BindingFlags
Bytes

A shared immutable byte slice (the equivalent of Rc<[u8]>).

CSET_A_2_Z
CSET_DIGITS
CSET_a_2_z
Checksum
Date
DateTime
EnumClass

Representation of an enum for dynamically, at runtime, querying the values of the enum and using them.

EnumValue

Representation of a single enum value of an EnumClass.

FileTest
FlagsBuilder

Builder for conveniently setting/unsetting flags and returning a Value.

FlagsClass

Representation of a flags for dynamically, at runtime, querying the values of the enum and using them

FlagsValue

Representation of a single flags value of a FlagsClass.

FormatSizeFlags
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
KeyFileFlags
MainContext
MainLoop
OPTION_REMAINING
ParamFlags
ParamSpec
Quark
STR_DELIMITERS
Source
SourceFuture

Represents a Future around a glib::Source. The future will be resolved once the source has provided a value

SourceStream

Represents a Stream around a glib::Source. The stream will be provide all values that are provided by the source

String

A mutable text buffer that grows automatically.

TimeVal
TimeZone
URI_RESERVED_CHARS_GENERIC_DELIMITERS
URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS
ValueArray
VariantTy

Describes Variant types.

VariantType

Describes Variant types.

Enums

ChecksumType
DateMonth
DateWeekday
FileError
KeyFileError
SeekType
TimeType
UserDirectory

Functions

access
assert_warning
assertion_message
assertion_message_cmpstr
assertion_message_expr
base64_decode
base64_encode
basename [
Deprecated
]
bit_nth_lsf
bit_nth_msf
bit_storage
build_filenamev
build_pathv
chdir
check_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

clear_error
compute_checksum_for_bytes
compute_checksum_for_data
compute_checksum_for_string
compute_hmac_for_bytes
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_for_display [
Deprecated
]
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
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.

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
test_assert_expected_messages_internal
test_bug
test_bug_base
test_fail
test_failed
test_incomplete
test_rand_double
test_rand_double_range
test_rand_int
test_rand_int_range
test_run
test_set_nonfatal_assertions
test_skip
test_subprocess
test_timer_elapsed
test_timer_last
test_timer_start
test_trap_assertions
test_trap_has_passed
test_trap_reached_timeout
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.

unix_signal_future

Create a Future that will resolve once the given UNIX signal is raised

unix_signal_future_with_priority

Create a Future that will resolve once the given UNIX signal is raised

unix_signal_stream

Create a Stream that will provide a value whenever the given UNIX signal is raised

unix_signal_stream_with_priority

Create a Stream that will provide a value whenever the given UNIX signal is raised

unlink
unsetenv
uri_escape_string
uri_list_extract_uris
uri_parse_scheme
uri_unescape_segment
uri_unescape_string
usleep
uuid_string_is_valid
uuid_string_random
variant_get_gtype
warn_message

Type Definitions

DateDay
DateYear
Time
TimeSpan