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 <francois.mockers@vleue.com>
This commit is contained in:
Benjamin Brienen 2024-09-21 22:52:46 +02:00 committed by GitHub
parent 66a474a9d9
commit 02a9ed4b0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 22 additions and 12 deletions

View File

@ -3,8 +3,7 @@ use crate::{
UntypedAssetId, UntypedAssetId,
}; };
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
use bevy_reflect::{std_traits::ReflectDefault, Reflect, TypePath}; use bevy_reflect::{std_traits::ReflectDefault, Reflect, ShortName, TypePath};
use bevy_utils::ShortName;
use crossbeam_channel::{Receiver, Sender}; use crossbeam_channel::{Receiver, Sender};
use std::{ use std::{
any::TypeId, any::TypeId,

View File

@ -246,7 +246,7 @@ pub enum Chain {
/// fn system_one() { println!("System 1 works!") } /// fn system_one() { println!("System 1 works!") }
/// fn system_two() { println!("System 2 works!") } /// fn system_two() { println!("System 2 works!") }
/// fn system_three() { println!("System 3 works!") } /// fn system_three() { println!("System 3 works!") }
/// ///
/// fn main() { /// fn main() {
/// let mut world = World::new(); /// let mut world = World::new();
/// let mut schedule = Schedule::default(); /// let mut schedule = Schedule::default();
@ -1582,7 +1582,7 @@ impl ScheduleGraph {
#[inline] #[inline]
fn get_node_name_inner(&self, id: &NodeId, report_sets: bool) -> String { fn get_node_name_inner(&self, id: &NodeId, report_sets: bool) -> String {
let mut name = match id { let name = match id {
NodeId::System(_) => { NodeId::System(_) => {
let name = self.systems[id.index()].get().unwrap().name().to_string(); let name = self.systems[id.index()].get().unwrap().name().to_string();
if report_sets { if report_sets {
@ -1607,9 +1607,15 @@ impl ScheduleGraph {
} }
} }
}; };
if self.settings.use_shortnames { #[cfg(feature = "bevy_reflect")]
name = bevy_utils::ShortName(&name).to_string(); {
if self.settings.use_shortnames {
bevy_reflect::ShortName(&name).to_string()
} else {
name
}
} }
#[cfg(not(feature = "bevy_reflect"))]
name name
} }
@ -2012,6 +2018,7 @@ pub struct ScheduleBuildSettings {
/// If set to true, node names will be shortened instead of the fully qualified type path. /// If set to true, node names will be shortened instead of the fully qualified type path.
/// ///
/// Defaults to `true`. /// Defaults to `true`.
#[cfg(feature = "bevy_reflect")]
pub use_shortnames: bool, pub use_shortnames: bool,
/// If set to true, report all system sets the conflicting systems are part of. /// If set to true, report all system sets the conflicting systems are part of.
/// ///
@ -2033,6 +2040,7 @@ impl ScheduleBuildSettings {
ambiguity_detection: LogLevel::Ignore, ambiguity_detection: LogLevel::Ignore,
hierarchy_detection: LogLevel::Warn, hierarchy_detection: LogLevel::Warn,
auto_insert_apply_deferred: true, auto_insert_apply_deferred: true,
#[cfg(feature = "bevy_reflect")]
use_shortnames: true, use_shortnames: true,
report_sets: true, report_sets: true,
} }

View File

@ -4,7 +4,9 @@ use std::marker::PhantomData;
use crate::Parent; use crate::Parent;
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
#[cfg(feature = "bevy_app")] #[cfg(feature = "bevy_app")]
use bevy_utils::{HashSet, ShortName}; use bevy_reflect::ShortName;
#[cfg(feature = "bevy_app")]
use bevy_utils::HashSet;
/// When enabled, runs [`check_hierarchy_component_has_valid_parent<T>`]. /// When enabled, runs [`check_hierarchy_component_has_valid_parent<T>`].
/// ///

View File

@ -10,7 +10,7 @@ keywords = ["bevy"]
rust-version = "1.76.0" rust-version = "1.76.0"
[features] [features]
default = ["smallvec", "debug"] default = ["smallvec", "debug", "alloc"]
# When enabled, provides Bevy-related reflection implementations # When enabled, provides Bevy-related reflection implementations
bevy = ["smallvec", "smol_str"] bevy = ["smallvec", "smol_str"]
glam = ["dep:glam"] glam = ["dep:glam"]
@ -25,6 +25,7 @@ debug_stack = []
documentation = ["bevy_reflect_derive/documentation"] documentation = ["bevy_reflect_derive/documentation"]
# Enables function reflection # Enables function reflection
functions = ["bevy_reflect_derive/functions"] functions = ["bevy_reflect_derive/functions"]
alloc = []
[dependencies] [dependencies]
# bevy # bevy

View File

@ -549,6 +549,7 @@ mod reflect;
mod reflectable; mod reflectable;
mod remote; mod remote;
mod set; mod set;
mod short_name;
mod struct_trait; mod struct_trait;
mod tuple; mod tuple;
mod tuple_struct; mod tuple_struct;
@ -615,6 +616,7 @@ pub use type_registry::*;
pub use bevy_reflect_derive::*; pub use bevy_reflect_derive::*;
pub use erased_serde; pub use erased_serde;
pub use short_name::ShortName;
extern crate alloc; extern crate alloc;
@ -2366,7 +2368,7 @@ bevy_reflect::tests::Test {
fn short_type_path() -> &'static str { fn short_type_path() -> &'static str {
static CELL: GenericTypePathCell = GenericTypePathCell::new(); static CELL: GenericTypePathCell = GenericTypePathCell::new();
CELL.get_or_insert::<Self, _>(|| bevy_utils::ShortName::of::<Self>().to_string()) CELL.get_or_insert::<Self, _>(|| ShortName::of::<Self>().to_string())
} }
fn type_ident() -> Option<&'static str> { fn type_ident() -> Option<&'static str> {

View File

@ -14,7 +14,7 @@
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// # use bevy_utils::ShortName; /// # use bevy_reflect::ShortName;
/// # /// #
/// # mod foo { /// # mod foo {
/// # pub mod bar { /// # pub mod bar {

View File

@ -25,8 +25,6 @@ pub mod prelude {
} }
pub mod futures; pub mod futures;
mod short_names;
pub use short_names::ShortName;
pub mod synccell; pub mod synccell;
pub mod syncunsafecell; pub mod syncunsafecell;