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