Skip to main content

glib/
lib.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3#![cfg_attr(docsrs, feature(doc_cfg))]
4#![allow(clippy::missing_safety_doc)]
5#![allow(clippy::manual_c_str_literals)]
6#![allow(renamed_and_removed_lints)]
7// Override docs references to point to locally generated docs
8// rustdoc-stripper-ignore-next
9//! [`Type`]: struct@Type
10//! [`StaticType`]: trait@types::StaticType
11//! [`Value`]: struct@Value
12//! [`Variant``]: struct@Variant
13//! [`StaticVariantType`]: trait@variant::StaticVariantType
14//! [`Error`]: struct@Error
15//! [`FileError`]: enum@FileError
16//! [`Object`]: struct@Object
17//! [`Rc<RefCell<T>>`]: mod@std::cell#introducing-mutability-inside-of-something-immutable
18//! [`IsA`]: trait@object::IsA
19//! [`Cast`]: trait@object::Cast
20//! [`ObjectExt`]: trait@object::ObjectExt
21//! [`wrapper!`]: macro@wrapper
22//! [`wrapper`]: mod@wrapper
23//! [`boxed`]: mod@boxed
24//! [`shared`]: mod@shared
25//! [mod@object]: mod@object
26//! [`translate`]: mod@translate
27#![doc = include_str!("../README.md")]
28
29// for macros
30extern crate self as glib;
31
32pub use bitflags;
33#[doc(hidden)]
34pub use glib_macros::cstr_bytes;
35pub use glib_macros::{
36    Boxed, Downgrade, Enum, ErrorDomain, Properties, SharedBoxed, ValueDelegate, Variant,
37    async_test, clone, closure, closure_local, derived_properties, flags, object_interface,
38    object_subclass,
39};
40pub use glib_sys as ffi;
41pub use gobject_sys as gobject_ffi;
42
43pub use self::{
44    FileError,
45    bookmark_file::BookmarkFile,
46    byte_array::ByteArray,
47    bytes::Bytes,
48    closure::{Closure, RustClosure},
49    enums::{EnumClass, EnumValue, FlagsBuilder, FlagsClass, FlagsValue, UserDirectory},
50    error::{BoolError, Error},
51    object::{BorrowedObject, Class, InitiallyUnowned, Interface, Object, SendWeakRef, WeakRef},
52    signal::{
53        Propagation, SignalHandlerId, signal_handler_block, signal_handler_disconnect,
54        signal_handler_unblock, signal_stop_emission_by_name,
55    },
56    types::{ILong, Pointer, Type, ULong},
57    value::{BoxedValue, SendValue, Value},
58    variant::{FixedSizeVariantArray, Variant},
59    variant_dict::VariantDict,
60    variant_iter::{VariantIter, VariantStrIter},
61    variant_type::{VariantTy, VariantTyIterator, VariantType},
62};
63
64// Hack for the time being to retrieve the current function's name as a string.
65// Based on the stdext cratelicensed under the MIT license.
66//
67// Copyright (c) 2020 Igor Aleksanov
68//
69// Previous attempts to get such a macro into std:
70// * https://github.com/rust-lang/rfcs/pull/466
71// * https://github.com/rust-lang/rfcs/pull/1719
72// * https://github.com/rust-lang/rfcs/issues/1743
73// * https://github.com/rust-lang/rfcs/pull/2818
74// * ...
75// rustdoc-stripper-ignore-next
76/// This macro returns the name of the enclosing function.
77/// As the internal implementation is based on the [`std::any::type_name`], this macro derives
78/// all the limitations of this function.
79///
80/// ## Examples
81///
82/// ```rust
83/// mod bar {
84///     pub fn sample_function() {
85///         assert!(glib::function_name!().ends_with("bar::sample_function"));
86///     }
87/// }
88///
89/// bar::sample_function();
90/// ```
91///
92/// [`std::any::type_name`]: https://doc.rust-lang.org/std/any/fn.type_name.html
93#[macro_export]
94macro_rules! function_name {
95    () => {{
96        // Okay, this is ugly, I get it. However, this is the best we can get on a stable rust.
97        fn f() {}
98        fn type_name_of<T>(_: T) -> &'static str {
99            std::any::type_name::<T>()
100        }
101        let name = type_name_of(f);
102        // `3` is the length of the `::f`.
103        &name[..name.len() - 3]
104    }};
105}
106
107pub mod clone;
108#[macro_use]
109pub mod wrapper;
110#[macro_use]
111pub mod boxed;
112#[macro_use]
113pub mod boxed_inline;
114#[macro_use]
115pub mod shared;
116#[macro_use]
117pub mod error;
118#[macro_use]
119pub mod object;
120
121mod boxed_any_object;
122pub use boxed_any_object::BoxedAnyObject;
123mod exit_code;
124pub use exit_code::{ExitCode, InvalidExitCode};
125
126pub mod collections;
127pub use collections::{List, PtrSlice, SList, Slice, StrV, StrVRef};
128
129pub use self::auto::*;
130#[allow(clippy::too_many_arguments)]
131#[allow(clippy::type_complexity)]
132#[allow(unused_imports)]
133#[allow(non_upper_case_globals)]
134#[allow(clippy::let_and_return)]
135mod auto;
136
137#[cfg(feature = "v2_74")]
138#[cfg_attr(docsrs, doc(cfg(feature = "v2_74")))]
139pub use self::gobject::SignalGroup;
140pub use self::gobject::{
141    Binding, BindingFlags, InterfaceInfo, ParamFlags, SignalFlags, TypeFlags, TypeInfo, TypeModule,
142    TypePlugin, TypeValueTable,
143};
144#[cfg(feature = "v2_72")]
145#[cfg_attr(docsrs, doc(cfg(feature = "v2_72")))]
146pub use self::gobject::{BindingGroup, BindingGroupBuilder};
147
148mod gobject;
149
150mod bookmark_file;
151mod byte_array;
152mod bytes;
153mod control_flow;
154pub use self::control_flow::ControlFlow;
155pub mod char;
156pub use self::char::{Char, UChar};
157mod checksum;
158pub mod closure;
159mod convert;
160pub use self::convert::*;
161pub mod enums;
162mod functions;
163pub use self::functions::*;
164mod key_file;
165pub mod prelude;
166pub mod signal;
167pub mod source;
168pub use self::source::*;
169#[macro_use]
170pub mod translate;
171mod gstring;
172pub use self::gstring::*;
173mod gstring_builder;
174pub use self::gstring_builder::GStringBuilder;
175pub mod types;
176mod unicollate;
177pub use self::unicollate::{CollationKey, FilenameCollationKey};
178mod utils;
179pub use self::utils::*;
180mod unichar;
181pub use self::unichar::*;
182mod main_context;
183pub use self::main_context::MainContextAcquireGuard;
184mod date;
185mod date_time;
186mod time_span;
187mod time_zone;
188pub use self::time_span::TimeSpan;
189pub mod value;
190pub mod variant;
191mod variant_dict;
192mod variant_iter;
193mod variant_type;
194pub use self::date::Date;
195mod value_array;
196pub use self::value_array::ValueArray;
197mod param_spec;
198pub use self::param_spec::*;
199pub mod property;
200mod quark;
201pub use self::quark::Quark;
202pub mod match_info;
203pub use self::match_info::MatchInfo;
204pub mod regex;
205#[macro_use]
206mod log;
207#[doc(hidden)]
208#[cfg(feature = "log_macros")]
209#[cfg_attr(docsrs, doc(cfg(feature = "log_macros")))]
210pub use rs_log;
211
212pub use self::log::{
213    LogField, LogHandlerId, LogLevel, LogLevels, log_default_handler, log_remove_handler,
214    log_set_always_fatal, log_set_default_handler, log_set_fatal_mask, log_set_handler,
215    log_set_writer_func, log_structured_array, log_unset_default_handler, log_variant,
216    log_writer_default, log_writer_format_fields, log_writer_journald, log_writer_standard_streams,
217    set_print_handler, set_printerr_handler, unset_print_handler, unset_printerr_handler,
218};
219#[cfg(feature = "v2_68")]
220pub use self::log::{log_writer_default_set_use_stderr, log_writer_default_would_drop};
221#[cfg(unix)]
222pub use self::log::{log_writer_is_journald, log_writer_supports_color};
223
224#[cfg(feature = "log")]
225#[cfg_attr(docsrs, doc(cfg(feature = "log")))]
226#[macro_use]
227mod bridged_logging;
228#[cfg(feature = "log")]
229#[cfg_attr(docsrs, doc(cfg(feature = "log")))]
230pub use self::bridged_logging::{
231    GlibLogger, GlibLoggerDomain, GlibLoggerFormat, rust_log_handler, rust_log_writer,
232};
233
234#[macro_use]
235pub mod subclass;
236
237#[cfg(feature = "futures")]
238mod main_context_futures;
239#[cfg(feature = "futures")]
240pub use main_context_futures::{JoinError, JoinHandle, SpawnWithinJoinHandle};
241#[cfg(feature = "futures")]
242mod source_futures;
243#[cfg(feature = "futures")]
244pub use self::source_futures::*;
245
246#[cfg(feature = "futures")]
247mod future_with_timeout;
248#[cfg(feature = "futures")]
249pub use self::future_with_timeout::*;
250
251mod thread_pool;
252pub use self::thread_pool::{ThreadHandle, ThreadPool};
253
254pub mod thread_guard;
255
256// rustdoc-stripper-ignore-next
257/// This is the log domain used by the [`clone!`][crate::clone!] macro. If you want to use a custom
258/// logger (it prints to stdout by default), you can set your own logger using the corresponding
259/// `log` functions.
260pub const CLONE_MACRO_LOG_DOMAIN: &str = "glib-rs-clone";