Skip to content

Commit 91fc332

Browse files
committed
Move enum exports to crate::enums
1 parent 537c6e0 commit 91fc332

File tree

26 files changed

+93
-68
lines changed

26 files changed

+93
-68
lines changed

crates/bevy_reflect/derive/src/derive_data.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ impl<'a> ReflectEnum<'a> {
888888
.map(|variant| variant.to_info_tokens(bevy_reflect_path));
889889

890890
let mut info = quote! {
891-
#bevy_reflect_path::EnumInfo::new::<Self>(&[
891+
#bevy_reflect_path::enums::EnumInfo::new::<Self>(&[
892892
#(#variants),*
893893
])
894894
};
@@ -1015,7 +1015,7 @@ impl<'a> EnumVariant<'a> {
10151015
};
10161016

10171017
let mut info = quote! {
1018-
#bevy_reflect_path::#info_struct::new(#args)
1018+
#bevy_reflect_path::enums::#info_struct::new(#args)
10191019
};
10201020

10211021
let custom_attributes = &self.attrs.custom_attributes;
@@ -1037,7 +1037,7 @@ impl<'a> EnumVariant<'a> {
10371037
}
10381038

10391039
quote! {
1040-
#bevy_reflect_path::VariantInfo::#info_variant(#info)
1040+
#bevy_reflect_path::enums::VariantInfo::#info_variant(#info)
10411041
}
10421042
}
10431043
}

crates/bevy_reflect/derive/src/from_reflect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream
9393
if let #bevy_reflect_path::ReflectRef::Enum(#ref_value) =
9494
#bevy_reflect_path::PartialReflect::reflect_ref(#ref_value)
9595
{
96-
match #bevy_reflect_path::Enum::variant_name(#ref_value) {
96+
match #bevy_reflect_path::enums::Enum::variant_name(#ref_value) {
9797
#match_branches
9898
name => panic!("variant with name `{}` does not exist on enum `{}`", name, <Self as #bevy_reflect_path::TypePath>::type_path()),
9999
}

crates/bevy_reflect/derive/src/impls/enums.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream
6262
let full_reflect_impl = impl_full_reflect(&where_clause_options);
6363
let common_methods = common_partial_reflect_methods(
6464
reflect_enum.meta(),
65-
|| Some(quote!(#bevy_reflect_path::enum_partial_eq)),
66-
|| Some(quote!(#bevy_reflect_path::enum_hash)),
65+
|| Some(quote!(#bevy_reflect_path::enums::enum_partial_eq)),
66+
|| Some(quote!(#bevy_reflect_path::enums::enum_hash)),
6767
);
6868
let clone_fn = reflect_enum.get_clone_impl();
6969

@@ -97,7 +97,7 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream
9797

9898
#auto_register
9999

100-
impl #impl_generics #bevy_reflect_path::Enum for #enum_path #ty_generics #where_reflect_clause {
100+
impl #impl_generics #bevy_reflect_path::enums::Enum for #enum_path #ty_generics #where_reflect_clause {
101101
fn field(&self, #ref_name: &str) -> #FQOption<&dyn #bevy_reflect_path::PartialReflect> {
102102
match #match_this {
103103
#(#enum_field,)*
@@ -140,8 +140,8 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream
140140
}
141141
}
142142

143-
fn iter_fields(&self) -> #bevy_reflect_path::VariantFieldIter {
144-
#bevy_reflect_path::VariantFieldIter::new(self)
143+
fn iter_fields(&self) -> #bevy_reflect_path::enums::VariantFieldIter {
144+
#bevy_reflect_path::enums::VariantFieldIter::new(self)
145145
}
146146

147147
#[inline]
@@ -169,15 +169,15 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream
169169
}
170170

171171
#[inline]
172-
fn variant_type(&self) -> #bevy_reflect_path::VariantType {
172+
fn variant_type(&self) -> #bevy_reflect_path::enums::VariantType {
173173
match #match_this {
174174
#(#enum_variant_type,)*
175175
_ => unreachable!(),
176176
}
177177
}
178178

179-
fn to_dynamic_enum(&self) -> #bevy_reflect_path::DynamicEnum {
180-
#bevy_reflect_path::DynamicEnum::from_ref::<Self>(self)
179+
fn to_dynamic_enum(&self) -> #bevy_reflect_path::enums::DynamicEnum {
180+
#bevy_reflect_path::enums::DynamicEnum::from_ref::<Self>(self)
181181
}
182182
}
183183

@@ -194,20 +194,20 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream
194194
) -> #FQResult<(), #bevy_reflect_path::ApplyError> {
195195
if let #bevy_reflect_path::ReflectRef::Enum(#ref_value) =
196196
#bevy_reflect_path::PartialReflect::reflect_ref(#ref_value) {
197-
if #bevy_reflect_path::Enum::variant_name(self) == #bevy_reflect_path::Enum::variant_name(#ref_value) {
197+
if #bevy_reflect_path::enums::Enum::variant_name(self) == #bevy_reflect_path::enums::Enum::variant_name(#ref_value) {
198198
// Same variant -> just update fields
199-
match #bevy_reflect_path::Enum::variant_type(#ref_value) {
200-
#bevy_reflect_path::VariantType::Struct => {
201-
for field in #bevy_reflect_path::Enum::iter_fields(#ref_value) {
199+
match #bevy_reflect_path::enums::Enum::variant_type(#ref_value) {
200+
#bevy_reflect_path::enums::VariantType::Struct => {
201+
for field in #bevy_reflect_path::enums::Enum::iter_fields(#ref_value) {
202202
let name = field.name().unwrap();
203-
if let #FQOption::Some(v) = #bevy_reflect_path::Enum::field_mut(self, name) {
203+
if let #FQOption::Some(v) = #bevy_reflect_path::enums::Enum::field_mut(self, name) {
204204
#bevy_reflect_path::PartialReflect::try_apply(v, field.value())?;
205205
}
206206
}
207207
}
208-
#bevy_reflect_path::VariantType::Tuple => {
209-
for (index, field) in ::core::iter::Iterator::enumerate(#bevy_reflect_path::Enum::iter_fields(#ref_value)) {
210-
if let #FQOption::Some(v) = #bevy_reflect_path::Enum::field_at_mut(self, index) {
208+
#bevy_reflect_path::enums::VariantType::Tuple => {
209+
for (index, field) in ::core::iter::Iterator::enumerate(#bevy_reflect_path::enums::Enum::iter_fields(#ref_value)) {
210+
if let #FQOption::Some(v) = #bevy_reflect_path::enums::Enum::field_at_mut(self, index) {
211211
#bevy_reflect_path::PartialReflect::try_apply(v, field.value())?;
212212
}
213213
}
@@ -216,7 +216,7 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream
216216
}
217217
} else {
218218
// New variant -> perform a switch
219-
match #bevy_reflect_path::Enum::variant_name(#ref_value) {
219+
match #bevy_reflect_path::enums::Enum::variant_name(#ref_value) {
220220
#(#variant_names => {
221221
#deref_this = #variant_constructors
222222
})*
@@ -309,7 +309,7 @@ fn generate_impls(reflect_enum: &ReflectEnum, ref_index: &Ident, ref_name: &Iden
309309
#unit{..} => #variant_index
310310
});
311311
enum_variant_type.push(quote! {
312-
#unit{..} => #bevy_reflect_path::VariantType::#variant_type_ident
312+
#unit{..} => #bevy_reflect_path::enums::VariantType::#variant_type_ident
313313
});
314314

315315
fn process_fields(

crates/bevy_reflect/src/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub(crate) use impl_custom_attribute_methods;
183183
#[cfg(test)]
184184
mod tests {
185185
use super::*;
186-
use crate::{type_info::Typed, TypeInfo, VariantInfo};
186+
use crate::{enums::VariantInfo, type_info::Typed, TypeInfo};
187187
use alloc::{format, string::String};
188188
use core::ops::RangeInclusive;
189189

crates/bevy_reflect/src/enums/dynamic_enum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use bevy_reflect_derive::impl_type_path;
22

33
use crate::{
4-
enum_debug, enum_hash, enum_partial_eq, ApplyError, DynamicStruct, DynamicTuple, Enum,
5-
PartialReflect, Reflect, ReflectKind, ReflectMut, ReflectOwned, ReflectRef, Struct, Tuple,
6-
TypeInfo, VariantFieldIter, VariantType,
4+
enums::{enum_debug, enum_hash, enum_partial_eq, Enum, VariantFieldIter, VariantType},
5+
ApplyError, DynamicStruct, DynamicTuple, PartialReflect, Reflect, ReflectKind, ReflectMut,
6+
ReflectOwned, ReflectRef, Struct, Tuple, TypeInfo,
77
};
88

99
use alloc::{boxed::Box, string::String};

crates/bevy_reflect/src/enums/enum_trait.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::generics::impl_generic_info_methods;
22
use crate::{
33
attributes::{impl_custom_attribute_methods, CustomAttributes},
4+
enums::{DynamicEnum, VariantInfo, VariantType},
45
type_info::impl_type_methods,
5-
DynamicEnum, Generics, PartialReflect, Type, TypePath, VariantInfo, VariantType,
6+
Generics, PartialReflect, Type, TypePath,
67
};
78
use alloc::{boxed::Box, format, string::String};
89
use bevy_platform::collections::HashMap;
@@ -325,7 +326,7 @@ impl<'a> VariantField<'a> {
325326
// Tests that need access to internal fields have to go here rather than in mod.rs
326327
#[cfg(test)]
327328
mod tests {
328-
use crate::*;
329+
use crate::{enums::*, Reflect};
329330

330331
#[derive(Reflect, Debug, PartialEq)]
331332
enum MyEnum {

crates/bevy_reflect/src/enums/helpers.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use crate::{utility::reflect_hasher, Enum, PartialReflect, ReflectRef, VariantType};
1+
use crate::{
2+
enums::{Enum, VariantType},
3+
utility::reflect_hasher,
4+
PartialReflect, ReflectRef,
5+
};
26
use core::{
37
fmt::Debug,
48
hash::{Hash, Hasher},

crates/bevy_reflect/src/enums/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Types and traits used to power [enum-like] operations via reflection.
2+
//!
3+
//! [enum-like]: https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html
14
mod dynamic_enum;
25
mod enum_trait;
36
mod helpers;
@@ -10,7 +13,7 @@ pub use variants::*;
1013

1114
#[cfg(test)]
1215
mod tests {
13-
use crate::*;
16+
use crate::{enums::*, *};
1417
use alloc::boxed::Box;
1518

1619
#[derive(Reflect, Debug, PartialEq)]

crates/bevy_reflect/src/from_reflect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub trait FromReflect: Reflect + Sized {
101101
/// ```
102102
///
103103
/// [`DynamicStruct`]: crate::DynamicStruct
104-
/// [`DynamicEnum`]: crate::DynamicEnum
104+
/// [`DynamicEnum`]: crate::enums::DynamicEnum
105105
#[derive(Clone)]
106106
pub struct ReflectFromReflect {
107107
from_reflect: fn(&dyn PartialReflect) -> Option<Box<dyn Reflect>>,

crates/bevy_reflect/src/impls/core/option.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ impl_reflect! {
1515

1616
#[cfg(test)]
1717
mod tests {
18-
use crate::{Enum, FromReflect, PartialReflect, TypeInfo, Typed, VariantInfo, VariantType};
18+
use crate::{
19+
enums::{Enum, VariantInfo, VariantType},
20+
FromReflect, PartialReflect, TypeInfo, Typed,
21+
};
1922
use bevy_reflect_derive::Reflect;
2023
use static_assertions::assert_impl_all;
2124

0 commit comments

Comments
 (0)