Skip to content

Commit 5d82339

Browse files
committed
Add .rustfmt.toml; manual tweaks to imports
1 parent 0dde85e commit 5d82339

File tree

16 files changed

+123
-101
lines changed

16 files changed

+123
-101
lines changed

.rustfmt.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md
2+
3+
# Orders imports by std:: -> third_party:: -> crate:: paths.
4+
#
5+
# Downside: it can mix pub/pub(crate)/private imports. To manage this, use two approaches:
6+
# 1. If many symbols appear, local inline modules `reexport_pub` and `reexport_crate`.
7+
# 2. For individual symbols, #[rustfmt::skip] attribute attached to the `use` statement.
8+
# We may change this appraoch in the future.
9+
group_imports = "StdExternalCrate"
10+
11+
# Normalizes a::{b, c::d}, a::e -> a::{b, e}, a::c::d.
12+
imports_granularity = "Module"

godot-bindings/src/godot_json.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
// Moving said types to `godot-bindings` would increase the cognitive overhead (since domain mapping is responsibility of `godot-codegen`, while godot-bindings is responsible for providing required resources & emitting the version).
1515
// In the future we might experiment with splitting said types into separate crates.
1616

17+
use std::fs;
18+
use std::path::Path;
19+
20+
use nanoserde::DeJson;
21+
1722
use crate::depend_on_custom_json::header_gen::generate_rust_binding;
1823
use crate::godot_version::validate_godot_version;
1924
use crate::{GodotVersion, StopWatch};
20-
use nanoserde::DeJson;
21-
use std::fs;
22-
use std::path::Path;
2325

26+
#[rustfmt::skip] // Do not reorder.
2427
// GDExtension headers are backward compatible (new incremental changes in general are exposed as additions to the existing API) while godot-rust simply ignores extra declarations in header file.
2528
// Therefore, latest headers should work fine for all the past and future Godot versions – as long as the engine remains unchanged.
2629
// [version-sync] [[

godot-bindings/src/import.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,27 @@ pub const ALL_VERSIONS: &[(u8, u8, u8)] = &[
3030
];
3131

3232
// [version-sync] [[
33-
// [line] #[cfg(feature = "api-$kebabVersion")]\npub use gdextension_api::version_$snakeVersion as prebuilt;\n
33+
// [line] #[cfg(feature = "api-$kebabVersion")]\npub use gdextension_api::version_$snakeVersion as prebuilt;
3434
#[cfg(feature = "api-4-1")]
3535
pub use gdextension_api::version_4_1 as prebuilt;
36-
3736
#[cfg(feature = "api-4-1-1")]
3837
pub use gdextension_api::version_4_1_1 as prebuilt;
39-
4038
#[cfg(feature = "api-4-1-2")]
4139
pub use gdextension_api::version_4_1_2 as prebuilt;
42-
4340
#[cfg(feature = "api-4-1-3")]
4441
pub use gdextension_api::version_4_1_3 as prebuilt;
45-
4642
#[cfg(feature = "api-4-1-4")]
4743
pub use gdextension_api::version_4_1_4 as prebuilt;
48-
4944
#[cfg(feature = "api-4-2")]
5045
pub use gdextension_api::version_4_2 as prebuilt;
51-
5246
#[cfg(feature = "api-4-2-1")]
5347
pub use gdextension_api::version_4_2_1 as prebuilt;
54-
5548
#[cfg(feature = "api-4-2-2")]
5649
pub use gdextension_api::version_4_2_2 as prebuilt;
57-
5850
#[cfg(feature = "api-4-3")]
5951
pub use gdextension_api::version_4_3 as prebuilt;
60-
6152
#[cfg(feature = "api-4-4")]
6253
pub use gdextension_api::version_4_4 as prebuilt;
63-
6454
// ]]
6555

6656
// If none of the api-* features are provided, use default prebuilt version (typically latest Godot stable release).

godot-core/src/builtin/collections/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub(crate) mod containers {
1818
}
1919

2020
// Re-export in godot::builtin::iter.
21+
#[rustfmt::skip] // Individual lines.
2122
pub(crate) mod iterators {
2223
pub use super::array::Iter as ArrayIter;
2324
pub use super::dictionary::Iter as DictIter;

godot-core/src/builtin/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ pub use crate::{array, dict, real, reals, varray, vdict};
2424

2525
#[doc(hidden)]
2626
pub mod __prelude_reexport {
27+
#[rustfmt::skip] // Do not reorder.
2728
use super::*;
28-
29-
// ------------------------------------------------------------------------------------------------------------------------------------------
30-
29+
3130
pub use aabb::*;
3231
pub use basis::*;
3332
pub use callable::*;
@@ -51,10 +50,9 @@ pub mod __prelude_reexport {
5150
pub use super::math::XformInv;
5251
pub use super::{EulerOrder, Side, VariantOperator, VariantType};
5352
pub use crate::{array, real, reals, varray, vdict, vslice};
54-
55-
// ------------------------------------------------------------------------------------------------------------------------------------------
56-
53+
5754
#[allow(deprecated)]
55+
#[rustfmt::skip] // Do not reorder.
5856
pub use crate::dict;
5957
}
6058

godot-core/src/builtin/real.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ mod real_mod {
164164
}
165165

166166
// Public symbols (note that macro `real!` is re-exported in `lib.rs`)
167+
#[rustfmt::skip] // Do not reorder.
167168
pub use real_mod::{real, real_consts};
168169

169170
// ----------------------------------------------------------------------------------------------------------------------------------------------

godot-core/src/classes/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ mod match_class;
2222

2323
// Re-exports all generated classes, interface traits and sidecar modules.
2424
pub use crate::gen::classes::*;
25-
2625
// Macro re-export.
2726
pub use crate::match_class;
2827

godot-core/src/global/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@
4242

4343
mod print;
4444

45-
pub use crate::{
46-
godot_error, godot_print, godot_print_rich, godot_script_error, godot_str, godot_warn,
47-
};
48-
4945
// Some enums are directly re-exported from crate::builtin.
5046
pub use crate::gen::central::global_enums::*;
5147
pub use crate::gen::utilities::*;
48+
pub use crate::{
49+
godot_error, godot_print, godot_print_rich, godot_script_error, godot_str, godot_warn,
50+
};
5251

5352
// ----------------------------------------------------------------------------------------------------------------------------------------------
5453
// Internal re-exports
5554

5655
// This is needed for generated classes to find symbols, even those that have been moved to crate::builtin.
5756
#[allow(unused_imports)] // micromanaging imports for generated code is not fun
57+
#[rustfmt::skip] // Do not reorder.
5858
pub(crate) use crate::builtin::{Corner, EulerOrder, Side};
5959

6060
// ----------------------------------------------------------------------------------------------------------------------------------------------

godot-core/src/init/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
77

8-
use std::sync::atomic::{AtomicBool, Ordering::Relaxed};
8+
use std::sync::atomic::{AtomicBool, Ordering};
99

1010
use godot_ffi as sys;
11-
1211
use sys::GodotFfi;
1312

1413
use crate::builtin::{GString, StringName};
1514
use crate::out;
1615

17-
pub use sys::GdextBuild;
18-
19-
pub use sys::is_main_thread;
20-
#[cfg(not(wasm_nothreads))]
21-
pub use sys::main_thread_id;
16+
mod reexport_pub {
17+
#[cfg(not(wasm_nothreads))]
18+
pub use super::sys::main_thread_id;
19+
pub use super::sys::{is_main_thread, GdextBuild};
20+
}
21+
pub use reexport_pub::*;
2222

2323
#[doc(hidden)]
2424
#[deny(unsafe_op_in_unsafe_fn)]
@@ -101,13 +101,13 @@ unsafe extern "C" fn ffi_initialize_layer<E: ExtensionLibrary>(
101101

102102
// TODO: Remove this workaround once after the upstream issue is resolved.
103103
if level == InitLevel::Scene {
104-
if !LEVEL_SERVERS_CORE_LOADED.load(Relaxed) {
104+
if !LEVEL_SERVERS_CORE_LOADED.load(Ordering::Relaxed) {
105105
try_load::<E>(InitLevel::Core);
106106
try_load::<E>(InitLevel::Servers);
107107
}
108108
} else if level == InitLevel::Core {
109109
// When it's normal initialization, the `Servers` level is normally initialized.
110-
LEVEL_SERVERS_CORE_LOADED.store(true, Relaxed);
110+
LEVEL_SERVERS_CORE_LOADED.store(true, Ordering::Relaxed);
111111
}
112112

113113
// SAFETY: Godot will call this from the main thread, after `__gdext_load_library` where the library is initialized,
@@ -133,7 +133,7 @@ unsafe extern "C" fn ffi_deinitialize_layer<E: ExtensionLibrary>(
133133
let _ = crate::private::handle_panic(ctx, || {
134134
if level == InitLevel::Core {
135135
// Once the CORE api is unloaded, reset the flag to initial state.
136-
LEVEL_SERVERS_CORE_LOADED.store(false, Relaxed);
136+
LEVEL_SERVERS_CORE_LOADED.store(false, Ordering::Relaxed);
137137
}
138138

139139
E::on_level_deinit(level);

godot-core/src/meta/mod.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,38 @@ pub(crate) mod sealed;
5959
pub mod error;
6060
pub mod inspect;
6161

62+
// Public re-exports
6263
pub use args::*;
6364
pub use class_name::ClassName;
6465
pub use godot_convert::{FromGodot, GodotConvert, ToGodot};
66+
pub use method_info::MethodInfo;
6567
pub use param_tuple::{InParamTuple, OutParamTuple, ParamTuple};
68+
pub use property_info::{PropertyHintInfo, PropertyInfo};
69+
#[cfg(feature = "trace")]
70+
pub use signature::trace;
71+
#[doc(hidden)]
72+
pub use signature::*;
6673
pub use traits::{ArrayElement, GodotType, PackedArrayElement};
6774
pub use uniform_object_deref::UniformObjectDeref;
6875

69-
pub(crate) use array_type_info::ArrayTypeInfo;
70-
pub(crate) use traits::{
71-
element_godot_type_name, element_variant_type, ffi_variant_type, ExtVariantType,
72-
GodotFfiVariant, GodotNullableFfi,
73-
};
74-
75-
use crate::registry::method::MethodParamOrReturnInfo;
76-
77-
pub(crate) use crate::{
78-
arg_into_ref, declare_arg_method, impl_asarg_by_ref, impl_asarg_by_value, impl_godot_as_self,
79-
};
8076
// Public due to signals emit() needing it. Should be made pub(crate) again if that changes.
8177
pub use crate::arg_into_owned;
8278

83-
#[doc(hidden)]
84-
pub use signature::*;
85-
86-
#[cfg(feature = "trace")]
87-
pub use signature::trace;
88-
89-
pub use method_info::MethodInfo;
90-
pub use property_info::{PropertyHintInfo, PropertyInfo};
79+
// Crate-local re-exports
80+
mod reexport_crate {
81+
pub(crate) use super::array_type_info::ArrayTypeInfo;
82+
pub(crate) use super::traits::{
83+
element_godot_type_name, element_variant_type, ffi_variant_type, ExtVariantType,
84+
GodotFfiVariant, GodotNullableFfi,
85+
};
86+
// Private imports for this module only.
87+
pub(super) use crate::registry::method::MethodParamOrReturnInfo;
88+
pub(crate) use crate::{
89+
arg_into_ref, declare_arg_method, impl_asarg_by_ref, impl_asarg_by_value,
90+
impl_godot_as_self,
91+
};
92+
}
93+
pub(crate) use reexport_crate::*;
9194

9295
// ----------------------------------------------------------------------------------------------------------------------------------------------
9396

0 commit comments

Comments
 (0)