Skip to main content

godot_core/
lib.rs

1#![cfg_attr(published_docs, feature(doc_cfg))]
2/*
3 * Copyright (c) godot-rust; Bromeon and contributors.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 */
8
9//! # Internal crate of [**godot-rust**](https://godot-rust.github.io)
10//!
11//! Do not depend on this crate directly, instead use the `godot` crate.
12//! No SemVer or other guarantees are provided.
13
14// Note that a lot of those are public, but the godot crate still has the final say on what it wants to re-export.
15// Doing fine-grained visibility restrictions on every level is a useless maintenance chore.
16pub mod builder;
17pub mod builtin;
18pub mod classes;
19#[cfg(all(since_api = "4.3", feature = "register-docs"))] #[cfg_attr(published_docs, doc(cfg(all(since_api = "4.3", feature = "register-docs"))))]
20pub mod docs;
21#[doc(hidden)]
22pub mod possibly_docs {
23    #[cfg(all(since_api = "4.3", feature = "register-docs"))] #[cfg_attr(published_docs, doc(cfg(all(since_api = "4.3", feature = "register-docs"))))]
24    pub use crate::docs::*;
25}
26pub mod global;
27pub mod init;
28pub mod meta;
29pub mod obj;
30pub mod registry;
31pub mod task;
32pub mod tools;
33
34mod storage;
35pub use godot_ffi as sys;
36
37pub use crate::private::{fetch_last_panic_context, set_gdext_hook};
38
39// ----------------------------------------------------------------------------------------------------------------------------------------------
40// Validations (see also godot/lib.rs)
41
42#[cfg(all(feature = "register-docs", before_api = "4.3"))] #[cfg_attr(published_docs, doc(cfg(all(feature = "register-docs", before_api = "4.3"))))]
43compile_error!("Generating editor docs for Rust symbols requires at least Godot 4.3.");
44
45// ----------------------------------------------------------------------------------------------------------------------------------------------
46// Generated code
47
48// Output of generated code. Mimics the file structure, symbols are re-exported.
49#[rustfmt::skip]
50#[allow(unused_imports, dead_code, non_upper_case_globals, non_snake_case)]
51#[allow(clippy::too_many_arguments, clippy::let_and_return, clippy::new_ret_no_self)]
52#[allow(clippy::let_unit_value)] // let args = ();
53#[allow(clippy::wrong_self_convention)] // to_string() is const
54#[allow(clippy::upper_case_acronyms)] // TODO remove this line once we transform names
55#[allow(clippy::needless_lifetimes)]  // the following explicit lifetimes could be elided: 'a
56#[allow(unreachable_code, clippy::unimplemented)] // TODO remove once #153 is implemented
57#[allow(unsafe_op_in_unsafe_fn)] // FFI delegation, safety delegated to Godot C API contract
58mod r#gen {
59    include!(concat!(env!("OUT_DIR"), "/mod.rs"));
60}
61
62// ----------------------------------------------------------------------------------------------------------------------------------------------
63// Hidden but accessible symbols
64
65/// Module which is used for deprecated warnings. It stays even if there is nothing currently deprecated.
66#[doc(hidden)]
67#[path = "deprecated.rs"]
68pub mod __deprecated;
69
70/// All internal machinery that is accessed by various gdext tools (e.g. proc macros).
71#[doc(hidden)]
72pub mod private;
73
74/// Re-export logging macro.
75#[doc(hidden)]
76pub use godot_ffi::out;
77
78// ----------------------------------------------------------------------------------------------------------------------------------------------
79
80/// Tests for code that must not compile.
81///
82/// To add a new one, simply add a new `__*` named function with a `compile_fail` doc attribute.
83mod no_compile_tests {
84    /// With Godot 4.6+, functions with required parameters accept `Gd<T>` instead of `Option<Gd<T>>`.
85    ///
86    /// ```compile_fail
87    /// use godot::prelude::*;
88    /// let mut node: Gd<Node> = unimplemented!();
89    /// let option = Some(node.clone());
90    /// let option: Option<&Gd<Node>> = option.as_ref();
91    ///
92    /// // Following must not compile since `add_child` accepts only required (non-null) arguments.
93    /// node.add_child(option);
94    /// ```
95    ///
96    /// Sanity check that without the last line, it _does_ compile. This catches any regressions in the previous statements that would not
97    /// be caught by the above `compile_fail` test.
98    /// ```no_run
99    /// use godot::prelude::*;
100    /// let mut node: Gd<Node> = unimplemented!();
101    /// let option = Some(node.clone());
102    /// let option: Option<&Gd<Node>> = option.as_ref();
103    /// ```
104    #[cfg(since_api = "4.6")] #[cfg_attr(published_docs, doc(cfg(since_api = "4.6")))]
105    fn __required_param_must_not_take_option() {}
106}