Skip to content

Commit 8d9a1ee

Browse files
authored
Merge pull request #1269 from godot-rust/qol/code-style
Code style: stricter imports
2 parents 0674858 + 5d82339 commit 8d9a1ee

File tree

216 files changed

+829
-648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

216 files changed

+829
-648
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_exe.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77

88
//! Commands related to Godot executable
99
10+
use std::fs;
11+
use std::path::{Path, PathBuf};
12+
use std::process::{Command, Output};
13+
14+
use regex::Regex;
15+
1016
use crate::godot_version::{parse_godot_version, validate_godot_version};
1117
use crate::header_gen::generate_rust_binding;
1218
use crate::watch::StopWatch;
1319
use crate::GodotVersion;
1420

15-
use regex::Regex;
16-
use std::fs;
17-
use std::path::{Path, PathBuf};
18-
use std::process::{Command, Output};
1921
// Note: CARGO_BUILD_TARGET_DIR and CARGO_TARGET_DIR are not set.
2022
// OUT_DIR would be standing to reason, but it's an unspecified path that cannot be referenced by CI.
2123
// const GODOT_VERSION_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/src/gen/godot_version.txt");

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/godot_version.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
// while all the functions included are used only with `custom-api` and `custom-api-json` features.
1010
#![cfg_attr(not(feature = "api-custom"), allow(unused_variables, dead_code))]
1111

12-
use crate::GodotVersion;
13-
use regex::{Captures, Regex};
1412
use std::error::Error;
1513
use std::str::FromStr;
1614

15+
use regex::{Captures, Regex};
16+
17+
use crate::GodotVersion;
18+
1719
pub fn parse_godot_version(version_str: &str) -> Result<GodotVersion, Box<dyn Error>> {
1820
// Format of the string emitted by `godot --version`:
1921
// https://github.com/godot-rust/gdext/issues/118#issuecomment-1465748123

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-bindings/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ mod godot_version;
4848
#[cfg(feature = "api-custom")]
4949
#[path = ""]
5050
mod depend_on_custom {
51-
use super::*;
5251
use std::borrow::Cow;
5352

53+
use super::*;
54+
5455
pub(crate) mod godot_exe;
5556
pub(crate) mod godot_version;
5657
pub(crate) mod header_gen;
@@ -82,10 +83,10 @@ pub use depend_on_custom::*;
8283
#[cfg(feature = "api-custom-json")]
8384
#[path = ""]
8485
mod depend_on_custom_json {
85-
use super::*;
86-
8786
use std::borrow::Cow;
8887

88+
use super::*;
89+
8990
pub(crate) mod godot_json;
9091
pub(crate) mod godot_version;
9192
pub(crate) mod header_gen;

godot-bindings/src/watch.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
*/
77

88
use std::fs::File;
9-
use std::io::BufWriter;
9+
use std::io::{BufWriter, Write};
1010
use std::path::Path;
1111
use std::time::{Duration, Instant};
1212

13-
use std::io::Write;
14-
1513
pub struct StopWatch {
1614
last_instant: Instant,
1715
metrics: Vec<Metric>,

godot-cell/src/borrow_state.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/// If a catastrophic error occurs, then the state will be poisoned. If the state is poisoned then that's
1919
/// almost certainly an implementation bug, and should never happen. But in an abundance of caution it is
2020
/// included to be safe.
21-
#[derive(Debug, Clone, PartialEq)]
21+
#[derive(Clone, PartialEq, Debug)]
2222
pub struct BorrowState {
2323
/// The number of `&T` references that are tracked.
2424
shared_count: usize,
@@ -267,7 +267,7 @@ impl Default for BorrowState {
267267
}
268268
}
269269

270-
#[derive(Debug, Clone, PartialEq, Eq)]
270+
#[derive(Clone, Eq, PartialEq, Debug)]
271271
pub enum BorrowStateErr {
272272
Poisoned(String),
273273
IsPoisoned,
@@ -300,16 +300,19 @@ impl From<String> for BorrowStateErr {
300300

301301
#[cfg(all(test, feature = "proptest"))]
302302
mod proptests {
303+
use proptest::arbitrary::Arbitrary;
304+
use proptest::collection::vec;
305+
use proptest::prelude::*;
306+
303307
use super::*;
304-
use proptest::{arbitrary::Arbitrary, collection::vec, prelude::*};
305308

306309
impl BorrowState {
307310
fn has_shared_reference(&self) -> bool {
308311
self.shared_count > 0
309312
}
310313
}
311314

312-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
315+
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
313316
enum Operation {
314317
IncShared,
315318
DecShared,
@@ -362,7 +365,7 @@ mod proptests {
362365
}
363366
}
364367

365-
#[derive(Debug, Clone, PartialEq, Eq)]
368+
#[derive(Clone, Eq, PartialEq, Debug)]
366369
struct OperationExecutor {
367370
vec: Vec<Operation>,
368371
}

godot-cell/tests/mock/blocking.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
use std::collections::HashMap;
1313
use std::error::Error;
1414
use std::marker::PhantomData;
15-
use std::sync::{atomic::AtomicUsize, Mutex, OnceLock};
15+
use std::sync::atomic::AtomicUsize;
16+
use std::sync::{Mutex, OnceLock};
1617
use std::time::Duration;
1718

1819
use godot_cell::blocking::{GdCell, InaccessibleGuard};

godot-cell/tests/mock/panicking.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
use std::collections::HashMap;
1313
use std::error::Error;
1414
use std::marker::PhantomData;
15-
use std::sync::{atomic::AtomicUsize, Mutex, OnceLock};
15+
use std::sync::atomic::AtomicUsize;
16+
use std::sync::{Mutex, OnceLock};
1617

1718
use godot_cell::panicking::{GdCell, InaccessibleGuard};
1819

0 commit comments

Comments
 (0)