Skip to content

Commit b34d5d4

Browse files
authored
feat: shorten import paths (#367)
# Summary where we previously did `pub use my_mod` we also use `pub use my_mod::*`, this should make imports everywhere prettier and should not be a breaking change
1 parent 7ca94df commit b34d5d4

File tree

18 files changed

+111
-94
lines changed

18 files changed

+111
-94
lines changed

crates/bevy_api_gen/src/context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ impl ReflectType<'_> {
8282
}
8383

8484
pub(crate) const DEF_PATHS_BMS_FROM_SCRIPT: [&str; 2] = [
85-
"bevy_mod_scripting_core::bindings::function::from::FromScript",
86-
"bindings::function::from::FromScript",
85+
"bevy_mod_scripting_core::bindings::FromScript",
86+
"bindings::FromScript",
8787
];
8888
pub(crate) const DEF_PATHS_BMS_INTO_SCRIPT: [&str; 2] = [
89-
"bevy_mod_scripting_core::bindings::function::into::IntoScript",
90-
"bindings::function::into::IntoScript",
89+
"bevy_mod_scripting_core::bindings::IntoScript",
90+
"bindings::IntoScript",
9191
];
9292

9393
pub(crate) const DEF_PATHS_REFLECT: [&str; 2] =

crates/bevy_api_gen/src/passes/cache_traits.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
use log::trace;
22
use rustc_hir::def_id::LOCAL_CRATE;
3+
use rustc_middle::ty::TyCtxt;
34
use rustc_span::Symbol;
45

56
use crate::{
67
Args, BevyCtxt, DEF_PATHS_BMS_FROM_SCRIPT, DEF_PATHS_BMS_INTO_SCRIPT,
78
DEF_PATHS_GET_TYPE_REGISTRATION, DEF_PATHS_REFLECT, STD_SOURCE_TRAITS,
89
};
910

11+
fn dump_traits(tcx: &TyCtxt) -> String{
12+
let mut buffer = String::new();
13+
for t in tcx.all_traits() {
14+
buffer.push_str(&tcx.def_path_str(t));
15+
buffer.push_str(", ");
16+
}
17+
buffer
18+
}
19+
1020
/// Finds and caches relevant traits, if they cannot be found throws an ICE
1121
pub(crate) fn cache_traits(ctxt: &mut BevyCtxt<'_>, _args: &Args) -> bool {
1222
let tcx = &ctxt.tcx;
@@ -35,15 +45,17 @@ pub(crate) fn cache_traits(ctxt: &mut BevyCtxt<'_>, _args: &Args) -> bool {
3545

3646
if !ctxt.cached_traits.has_all_bms_traits() {
3747
panic!(
38-
"Could not find all bms traits in crate: {}",
39-
tcx.crate_name(LOCAL_CRATE)
48+
"Could not find all bms traits in crate: {}. Available traits: {}",
49+
tcx.crate_name(LOCAL_CRATE),
50+
dump_traits(tcx)
4051
)
4152
}
4253

4354
if !ctxt.cached_traits.has_all_bevy_traits() {
4455
panic!(
45-
"Could not find all reflect traits in crate: {}, did bootstrapping go wrong?",
46-
tcx.crate_name(LOCAL_CRATE)
56+
"Could not find all reflect traits in crate: {}, did bootstrapping go wrong?. Available traits: {}",
57+
tcx.crate_name(LOCAL_CRATE),
58+
dump_traits(tcx)
4759
)
4860
}
4961

crates/bevy_mod_scripting_core/src/bindings/access_map.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,6 @@ impl DisplayCodeLocation for Option<std::panic::Location<'_>> {
713713
}
714714
}
715715

716-
#[macro_export]
717716
/// A macro for claiming access to a value for reading
718717
macro_rules! with_access_read {
719718
($access_map:expr, $id:expr, $msg:expr, $body:block) => {{
@@ -731,7 +730,7 @@ macro_rules! with_access_read {
731730
}};
732731
}
733732

734-
#[macro_export]
733+
pub(crate) use with_access_read;
735734
/// A macro for claiming access to a value for writing
736735
macro_rules! with_access_write {
737736
($access_map:expr, $id:expr, $msg:expr, $body:block) => {
@@ -748,8 +747,8 @@ macro_rules! with_access_write {
748747
}
749748
};
750749
}
750+
pub(crate) use with_access_write;
751751

752-
#[macro_export]
753752
/// A macro for claiming global access
754753
macro_rules! with_global_access {
755754
($access_map:expr, $msg:expr, $body:block) => {
@@ -771,6 +770,8 @@ macro_rules! with_global_access {
771770
};
772771
}
773772

773+
pub(crate) use with_global_access;
774+
774775
#[cfg(test)]
775776
mod test {
776777
use super::*;

crates/bevy_mod_scripting_core/src/bindings/function/arg_meta.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use std::{ffi::OsString, path::PathBuf};
44

55
use crate::{
6-
bindings::{script_value::ScriptValue, ReflectReference},
7-
docgen::typed_through::TypedThrough,
6+
bindings::{ScriptValue, ReflectReference},
7+
docgen::TypedThrough,
88
};
99

1010
use super::{

crates/bevy_mod_scripting_core/src/bindings/function/from_ref.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
//! Contains the [`FromScriptRef`] trait and its implementations.
22
33
use std::{any::TypeId, ffi::OsString, path::PathBuf};
4-
54
use bevy::reflect::{
65
DynamicEnum, DynamicList, DynamicMap, DynamicTuple, DynamicVariant, Map, PartialReflect,
76
};
8-
97
use crate::{
10-
bindings::{function::from::FromScript, WorldGuard},
8+
bindings::{match_by_type, WorldGuard, FromScript},
119
error::InteropError,
12-
match_by_type,
1310
reflection_extensions::TypeInfoExtensions,
1411
ScriptValue,
1512
};

crates/bevy_mod_scripting_core/src/bindings/function/into.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
//! Implementations of the [`IntoScript`] trait for various types.
22
33
use std::{borrow::Cow, collections::HashMap, ffi::OsString, path::PathBuf};
4-
54
use bevy::reflect::Reflect;
65

7-
use crate::{
8-
bindings::{script_value::ScriptValue, ReflectReference, WorldGuard},
9-
error::InteropError,
10-
self_type_dependency_only,
11-
};
12-
13-
use super::{
14-
from::Val,
15-
script_function::{DynamicScriptFunction, DynamicScriptFunctionMut},
16-
};
6+
use crate::{bindings::{ReflectReference, ScriptValue, WorldGuard}, error::InteropError, private::self_type_dependency_only};
7+
use super::{DynamicScriptFunction, DynamicScriptFunctionMut, Val};
178

189
/// Converts a value into a [`ScriptValue`].
1910
pub trait IntoScript {

crates/bevy_mod_scripting_core/src/bindings/function/into_ref.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub trait IntoScriptRef {
2626
) -> Result<ScriptValue, InteropError>;
2727
}
2828

29-
#[macro_export]
3029
/// a utility for matching types by their [`std::any::TypeId`]
30+
#[macro_export]
3131
macro_rules! match_by_type {
3232
(match $on:ident {$($id:ident : $ty:ty => $conv:expr),*}) => {
3333
match $on {
@@ -39,6 +39,8 @@ macro_rules! match_by_type {
3939
};
4040
}
4141

42+
pub use match_by_type;
43+
4244
#[macro_export]
4345
/// Downcasts a reference into a value of a given type or returns an error if the downcast fails.
4446
macro_rules! downcast_into_value {

crates/bevy_mod_scripting_core/src/bindings/function/mod.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
//! Abstractions to do with dynamic script functions
22
3-
pub mod arg_meta;
4-
pub mod from;
5-
pub mod from_ref;
6-
pub mod into;
7-
pub mod into_ref;
8-
pub mod namespace;
9-
pub mod script_function;
10-
pub mod type_dependencies;
3+
crate::private::export_all_in_modules!{
4+
arg_meta,
5+
from,
6+
from_ref,
7+
into,
8+
into_ref,
9+
namespace,
10+
script_function,
11+
type_dependencies
12+
}
1113

1214
#[cfg(test)]
1315
#[allow(dead_code)]

crates/bevy_mod_scripting_core/src/bindings/function/type_dependencies.rs

+1-26
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::{
66
};
77
use crate::{
88
bindings::{ReflectReference, WorldGuard},
9-
error::InteropError,
9+
error::InteropError, private::{no_type_dependencies, self_type_dependency_only},
1010
};
1111
use bevy::reflect::{FromReflect, GetTypeRegistration, TypeRegistry, Typed};
1212
use std::collections::HashMap;
@@ -18,31 +18,6 @@ pub trait GetTypeDependencies {
1818
fn register_type_dependencies(registry: &mut TypeRegistry);
1919
}
2020

21-
#[macro_export]
22-
/// A macro for implementing [`GetTypeDependencies`] for types with no type dependencies.
23-
macro_rules! no_type_dependencies {
24-
($($path:path),*) => {
25-
$(
26-
impl $crate::bindings::function::type_dependencies::GetTypeDependencies for $path {
27-
fn register_type_dependencies(_registry: &mut bevy::reflect::TypeRegistry) {}
28-
}
29-
)*
30-
};
31-
}
32-
33-
#[macro_export]
34-
/// A macro for implementing [`GetTypeDependencies`] for types that only depend on themselves.
35-
macro_rules! self_type_dependency_only {
36-
($($path:ty),*) => {
37-
$(
38-
impl $crate::bindings::function::type_dependencies::GetTypeDependencies for $path {
39-
fn register_type_dependencies(registry: &mut bevy::reflect::TypeRegistry) {
40-
registry.register::<$path>();
41-
}
42-
}
43-
)*
44-
};
45-
}
4621

4722
macro_rules! recursive_type_dependencies {
4823
($( ($path:ty where $($bound:ident : $($bound_val:path);*),* $(,,const $const:ident : $const_ty:ty)? $(=> with $self_:ident)?) ),* ) => {

crates/bevy_mod_scripting_core/src/bindings/globals/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use bevy::{ecs::system::Resource, utils::hashbrown::HashMap};
1010
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
1111
use std::{any::TypeId, borrow::Cow, sync::Arc};
1212

13-
pub mod core;
13+
crate::private::export_all_in_modules!{
14+
core
15+
}
1416

1517
/// A send + sync wrapper around the [`ScriptGlobalsRegistry`].
1618
#[derive(Default, Resource, Clone)]
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//! Abstractions to help with creating bindings between bevy and scripting languages.
22
3-
pub mod access_map;
4-
pub mod allocator;
5-
pub mod function;
6-
pub mod globals;
7-
pub mod pretty_print;
8-
pub mod query;
9-
pub mod reference;
10-
pub mod schedule;
11-
pub mod script_system;
12-
pub mod script_value;
13-
pub mod world;
14-
15-
pub use {allocator::*, query::*, reference::*, world::*};
3+
crate::private::export_all_in_modules! {
4+
access_map,
5+
allocator,
6+
function,
7+
globals,
8+
pretty_print,
9+
query,
10+
reference,
11+
schedule,
12+
script_system,
13+
script_value,
14+
world,
15+
}

crates/bevy_mod_scripting_core/src/bindings/pretty_print.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::reflection_extensions::{FakeType, TypeIdExtensions};
44

5-
use super::{
5+
use crate::bindings::{
66
access_map::ReflectAccessId, script_value::ScriptValue, ReflectAllocationId, ReflectBase,
77
ReflectBaseType, ReflectReference, WorldGuard,
88
};

crates/bevy_mod_scripting_core/src/bindings/query.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Utilities for querying the world.
22
3-
use super::{ReflectReference, WorldAccessGuard};
4-
use crate::{error::InteropError, with_global_access};
3+
use super::{with_global_access, ReflectReference, WorldAccessGuard};
4+
use crate::error::InteropError;
55
use bevy::{
66
ecs::{
77
component::ComponentId,

crates/bevy_mod_scripting_core/src/bindings/reference.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//! we need wrapper types which have owned and ref variants.
77
use super::{access_map::ReflectAccessId, WorldGuard};
88
use crate::{
9-
bindings::ReflectAllocationId,
9+
bindings::{with_access_read, with_access_write, ReflectAllocationId},
1010
error::InteropError,
1111
reflection_extensions::{PartialReflectExt, TypeIdExtensions},
12-
with_access_read, with_access_write, ReflectAllocator,
12+
ReflectAllocator,
1313
};
1414
use bevy::{
1515
ecs::{

crates/bevy_mod_scripting_core/src/bindings/world.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,15 @@ use super::{
99
access_map::{
1010
AccessCount, AccessMapKey, AnyAccessMap, DynamicSystemMeta, ReflectAccessId,
1111
ReflectAccessKind, SubsetAccessMap,
12-
},
13-
function::{
12+
}, function::{
1413
namespace::Namespace,
1514
script_function::{AppScriptFunctionRegistry, DynamicScriptFunction, FunctionCallContext},
16-
},
17-
pretty_print::DisplayWithWorld,
18-
schedule::AppScheduleRegistry,
19-
script_value::ScriptValue,
20-
AppReflectAllocator, ReflectBase, ReflectBaseType, ReflectReference,
21-
ScriptComponentRegistration, ScriptResourceRegistration, ScriptTypeRegistration,
15+
}, pretty_print::DisplayWithWorld, schedule::AppScheduleRegistry, script_value::ScriptValue, with_global_access, AppReflectAllocator, ReflectBase, ReflectBaseType, ReflectReference, ScriptComponentRegistration, ScriptResourceRegistration, ScriptTypeRegistration
2216
};
2317
use crate::{
24-
bindings::function::{from::FromScript, from_ref::FromScriptRef},
18+
bindings::{function::{from::FromScript, from_ref::FromScriptRef}, with_access_read, with_access_write},
2519
error::InteropError,
2620
reflection_extensions::PartialReflectExt,
27-
with_access_read, with_access_write, with_global_access,
2821
};
2922
use bevy::{
3023
app::AppExit,
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! Documentation generation for scripting languages.
22
3-
pub mod info;
4-
pub mod typed_through;
3+
crate::private::export_all_in_modules! {
4+
info,
5+
typed_through
6+
}

crates/bevy_mod_scripting_core/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ pub mod reflection_extensions;
4040
pub mod runtime;
4141
pub mod script;
4242

43+
pub(crate) mod private;
44+
4345
#[derive(SystemSet, Hash, Debug, Eq, PartialEq, Clone)]
4446
/// Labels for various BMS systems
4547
pub enum ScriptingSystemSet {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! This module contains private functions and modules that are used internally by the crate.
2+
3+
macro_rules! export_all_in_modules {
4+
( $( $module:ident ),* $(,)? ) => {
5+
$(
6+
pub mod $module;
7+
)*
8+
pub use {
9+
$( $module::*, )*
10+
};
11+
};
12+
}
13+
14+
/// A macro for implementing [`GetTypeDependencies`] for types with no type dependencies.
15+
macro_rules! no_type_dependencies {
16+
($($path:path),*) => {
17+
$(
18+
impl $crate::bindings::function::type_dependencies::GetTypeDependencies for $path {
19+
fn register_type_dependencies(_registry: &mut bevy::reflect::TypeRegistry) {}
20+
}
21+
)*
22+
};
23+
}
24+
25+
/// A macro for implementing [`GetTypeDependencies`] for types that only depend on themselves.
26+
macro_rules! self_type_dependency_only {
27+
($($path:ty),*) => {
28+
$(
29+
impl $crate::bindings::function::type_dependencies::GetTypeDependencies for $path {
30+
fn register_type_dependencies(registry: &mut bevy::reflect::TypeRegistry) {
31+
registry.register::<$path>();
32+
}
33+
}
34+
)*
35+
};
36+
}
37+
38+
pub(crate) use {export_all_in_modules, no_type_dependencies, self_type_dependency_only};

0 commit comments

Comments
 (0)