Skip to content

Commit 02a9ed4

Browse files
move ShortName to bevy_reflect (#15340)
# Objective - Goal is to minimize bevy_utils #11478 ## Solution - Move the file short_name wholesale into bevy_reflect ## Testing - Unit tests - CI ## Migration Guide - References to `bevy_utils::ShortName` should instead now be `bevy_reflect::ShortName`. --------- Co-authored-by: François Mockers <[email protected]>
1 parent 66a474a commit 02a9ed4

File tree

7 files changed

+22
-12
lines changed

7 files changed

+22
-12
lines changed

crates/bevy_asset/src/handle.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use crate::{
33
UntypedAssetId,
44
};
55
use bevy_ecs::prelude::*;
6-
use bevy_reflect::{std_traits::ReflectDefault, Reflect, TypePath};
7-
use bevy_utils::ShortName;
6+
use bevy_reflect::{std_traits::ReflectDefault, Reflect, ShortName, TypePath};
87
use crossbeam_channel::{Receiver, Sender};
98
use std::{
109
any::TypeId,

crates/bevy_ecs/src/schedule/schedule.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ pub enum Chain {
246246
/// fn system_one() { println!("System 1 works!") }
247247
/// fn system_two() { println!("System 2 works!") }
248248
/// fn system_three() { println!("System 3 works!") }
249-
///
249+
///
250250
/// fn main() {
251251
/// let mut world = World::new();
252252
/// let mut schedule = Schedule::default();
@@ -1582,7 +1582,7 @@ impl ScheduleGraph {
15821582

15831583
#[inline]
15841584
fn get_node_name_inner(&self, id: &NodeId, report_sets: bool) -> String {
1585-
let mut name = match id {
1585+
let name = match id {
15861586
NodeId::System(_) => {
15871587
let name = self.systems[id.index()].get().unwrap().name().to_string();
15881588
if report_sets {
@@ -1607,9 +1607,15 @@ impl ScheduleGraph {
16071607
}
16081608
}
16091609
};
1610-
if self.settings.use_shortnames {
1611-
name = bevy_utils::ShortName(&name).to_string();
1610+
#[cfg(feature = "bevy_reflect")]
1611+
{
1612+
if self.settings.use_shortnames {
1613+
bevy_reflect::ShortName(&name).to_string()
1614+
} else {
1615+
name
1616+
}
16121617
}
1618+
#[cfg(not(feature = "bevy_reflect"))]
16131619
name
16141620
}
16151621

@@ -2012,6 +2018,7 @@ pub struct ScheduleBuildSettings {
20122018
/// If set to true, node names will be shortened instead of the fully qualified type path.
20132019
///
20142020
/// Defaults to `true`.
2021+
#[cfg(feature = "bevy_reflect")]
20152022
pub use_shortnames: bool,
20162023
/// If set to true, report all system sets the conflicting systems are part of.
20172024
///
@@ -2033,6 +2040,7 @@ impl ScheduleBuildSettings {
20332040
ambiguity_detection: LogLevel::Ignore,
20342041
hierarchy_detection: LogLevel::Warn,
20352042
auto_insert_apply_deferred: true,
2043+
#[cfg(feature = "bevy_reflect")]
20362044
use_shortnames: true,
20372045
report_sets: true,
20382046
}

crates/bevy_hierarchy/src/valid_parent_check_plugin.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use std::marker::PhantomData;
44
use crate::Parent;
55
use bevy_ecs::prelude::*;
66
#[cfg(feature = "bevy_app")]
7-
use bevy_utils::{HashSet, ShortName};
7+
use bevy_reflect::ShortName;
8+
#[cfg(feature = "bevy_app")]
9+
use bevy_utils::HashSet;
810

911
/// When enabled, runs [`check_hierarchy_component_has_valid_parent<T>`].
1012
///

crates/bevy_reflect/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ keywords = ["bevy"]
1010
rust-version = "1.76.0"
1111

1212
[features]
13-
default = ["smallvec", "debug"]
13+
default = ["smallvec", "debug", "alloc"]
1414
# When enabled, provides Bevy-related reflection implementations
1515
bevy = ["smallvec", "smol_str"]
1616
glam = ["dep:glam"]
@@ -25,6 +25,7 @@ debug_stack = []
2525
documentation = ["bevy_reflect_derive/documentation"]
2626
# Enables function reflection
2727
functions = ["bevy_reflect_derive/functions"]
28+
alloc = []
2829

2930
[dependencies]
3031
# bevy

crates/bevy_reflect/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ mod reflect;
549549
mod reflectable;
550550
mod remote;
551551
mod set;
552+
mod short_name;
552553
mod struct_trait;
553554
mod tuple;
554555
mod tuple_struct;
@@ -615,6 +616,7 @@ pub use type_registry::*;
615616

616617
pub use bevy_reflect_derive::*;
617618
pub use erased_serde;
619+
pub use short_name::ShortName;
618620

619621
extern crate alloc;
620622

@@ -2366,7 +2368,7 @@ bevy_reflect::tests::Test {
23662368

23672369
fn short_type_path() -> &'static str {
23682370
static CELL: GenericTypePathCell = GenericTypePathCell::new();
2369-
CELL.get_or_insert::<Self, _>(|| bevy_utils::ShortName::of::<Self>().to_string())
2371+
CELL.get_or_insert::<Self, _>(|| ShortName::of::<Self>().to_string())
23702372
}
23712373

23722374
fn type_ident() -> Option<&'static str> {

crates/bevy_utils/src/short_names.rs renamed to crates/bevy_reflect/src/short_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// # Examples
1515
///
1616
/// ```rust
17-
/// # use bevy_utils::ShortName;
17+
/// # use bevy_reflect::ShortName;
1818
/// #
1919
/// # mod foo {
2020
/// # pub mod bar {

crates/bevy_utils/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ pub mod prelude {
2525
}
2626

2727
pub mod futures;
28-
mod short_names;
29-
pub use short_names::ShortName;
3028
pub mod synccell;
3129
pub mod syncunsafecell;
3230

0 commit comments

Comments
 (0)