Skip to content

Commit

Permalink
messy rebase & ci
Browse files Browse the repository at this point in the history
  • Loading branch information
soqb committed Jan 14, 2023
1 parent 37d5a1a commit b011a37
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 35 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub struct AssetServerInternal {
/// use bevy_asset::{AssetServer, Handle};
/// use bevy_ecs::prelude::{Commands, Res};
///
/// # #[derive(Debug, bevy_reflect::TypeUuid)]
/// # #[derive(Debug, bevy_reflect::TypeUuid, bevy_reflect::TypePath)]
/// # #[uuid = "00000000-0000-0000-0000-000000000000"]
/// # struct Image;
///
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ use std::marker::PhantomData;
/// ```
/// # use bevy_pbr::{Material, MaterialMeshBundle};
/// # use bevy_ecs::prelude::*;
/// # use bevy_reflect::TypeUuid;
/// # use bevy_reflect::{TypeUuid, TypePath};
/// # use bevy_render::{render_resource::{AsBindGroup, ShaderRef}, texture::Image, color::Color};
/// # use bevy_asset::{Handle, AssetServer, Assets};
///
/// #[derive(AsBindGroup, TypeUuid, Debug, Clone)]
/// #[derive(AsBindGroup, TypeUuid, TypePath, Debug, Clone)]
/// #[uuid = "f690fdae-d598-45ab-8225-97e2a3f056e0"]
/// pub struct CustomMaterial {
/// // Uniform bindings must implement `ShaderType`, which will be used to convert the value to
Expand Down
25 changes: 11 additions & 14 deletions crates/bevy_reflect/bevy_reflect_derive/src/derive_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl<'a> ReflectDerive<'a> {
}
}
if let Some(path) = &mut alias_type_path {
let ident = alias_type_name.unwrap_or(input.ident.clone());
let ident = alias_type_name.unwrap_or_else(|| input.ident.clone());
path.segments.push(PathSegment::from(ident));
} else if let Some(name) = alias_type_name {
return Err(syn::Error::new(
Expand Down Expand Up @@ -273,9 +273,9 @@ impl<'a> ReflectDerive<'a> {

pub fn meta(&self) -> &ReflectMeta<'a> {
match self {
ReflectDerive::Struct(data) => data.meta(),
ReflectDerive::TupleStruct(data) => data.meta(),
ReflectDerive::UnitStruct(data) => data.meta(),
ReflectDerive::Struct(data)
| ReflectDerive::TupleStruct(data)
| ReflectDerive::UnitStruct(data) => data.meta(),
ReflectDerive::Enum(data) => data.meta(),
ReflectDerive::Value(meta) => meta,
}
Expand Down Expand Up @@ -486,15 +486,16 @@ pub(crate) enum PathToType<'a> {
/// The type must be able to be named from just its name.
///
/// May have a seperate alias path used for the `TypePath` implementation.
///
///
/// Module and crate are found with [`module_path!()`](core::module_path),
/// if there is no alias specified.
Internal {
name: &'a Ident,
alias: Option<Path>,
},
/// Any [`syn::Type`] with only a defined `type_path` and `short_type_path`.
#[allow(dead_code)] // Not currently used but may be useful in the future due to its generality.
#[allow(dead_code)]
// Not currently used but may be useful in the future due to its generality.
Anonymous {
qualified_type: Type,
long_type_path: proc_macro2::TokenStream,
Expand Down Expand Up @@ -542,8 +543,7 @@ impl<'a> PathToType<'a> {
/// [external]: PathToType::External
pub fn is_aliased(&self) -> bool {
match self {
Self::Internal { alias, .. } => alias.is_some(),
Self::External { alias, .. } => alias.is_some(),
Self::Internal { alias, .. } | Self::External { alias, .. } => alias.is_some(),
_ => false,
}
}
Expand All @@ -553,10 +553,7 @@ impl<'a> PathToType<'a> {
///
/// This is false for primitives and anonymous paths.
pub fn is_named(&self) -> bool {
match self {
Self::Primitive(_) | Self::Anonymous { .. } => false,
_ => true,
}
matches!(self, Self::Internal { .. } | Self::External { .. })
}

/// Returns an expression for an `AsRef<str>`.
Expand Down Expand Up @@ -629,7 +626,7 @@ impl<'a> PathToType<'a> {

/// Returns the name of the type. This is not necessarily a valid qualified path to the type.
pub fn ident(&self) -> Option<&Ident> {
self.named_as_ident().or_else(|| match self {
self.named_as_ident().or(match self {
Self::Primitive(ident) => Some(ident),
_ => None,
})
Expand All @@ -644,4 +641,4 @@ impl<'a> ToTokens for PathToType<'a> {
Self::Anonymous { qualified_type, .. } => qualified_type.to_tokens(tokens),
}
}
}
}
6 changes: 3 additions & 3 deletions crates/bevy_reflect/bevy_reflect_derive/src/impls/typed.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use quote::quote;
use syn::{GenericParam, LitStr, spanned::Spanned};
use syn::{spanned::Spanned, GenericParam, LitStr};

use crate::derive_data::{PathToType, ReflectMeta};

Expand All @@ -8,14 +8,14 @@ pub(crate) fn type_path_generator(meta: &ReflectMeta) -> proc_macro2::TokenStrea
let path_to_type = meta.path_to_type();
let generics = meta.generics();
let bevy_reflect_path = meta.bevy_reflect_path();

if let PathToType::Primitive(name) = path_to_type {
let name = LitStr::new(&name.to_string(), name.span());
return quote! {
#bevy_reflect_path::utility::TypePathStorage::new_primitive(#name)
};
}

// Whether to use `GenericTypedCell` is not dependent on lifetimes
// (which all have to be 'static anyway).
let is_generic = !generics
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_reflect/bevy_reflect_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn impl_reflect_value(input: TokenStream) -> TokenStream {
let def = parse_macro_input!(input as ReflectValueDef);

let default_name = &def.type_path.segments.last().unwrap().ident;
let path_to_type = if !def.type_path.leading_colon.is_some() && def.alias.is_empty() {
let path_to_type = if def.type_path.leading_colon.is_none() && def.alias.is_empty() {
PathToType::Primitive(default_name)
} else {
PathToType::External {
Expand Down Expand Up @@ -217,7 +217,7 @@ pub fn impl_from_reflect_value(input: TokenStream) -> TokenStream {
let def = parse_macro_input!(input as ReflectValueDef);

let default_name = &def.type_path.segments.last().unwrap().ident;
let path_to_type = if !def.type_path.leading_colon.is_some() && def.alias.is_empty() {
let path_to_type = if def.type_path.leading_colon.is_none() && def.alias.is_empty() {
PathToType::Primitive(default_name)
} else {
PathToType::External {
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_reflect/src/impls/glam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ impl_reflect_struct!(
w: u32,
}
);

impl_reflect_struct!(
#[reflect(Debug, PartialEq, Default)]
#[type_path = "glam"]
Expand Down
13 changes: 6 additions & 7 deletions crates/bevy_reflect/src/impls/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,19 +1133,19 @@ impl_type_path_stored!(|| TypePathStorage::new_named(
"core::borrow"
), impl for Cow<'static, str>);

impl GetTypeRegistration for Cow<'static, str>c Path {
impl GetTypeRegistration for Cow<'static, str> {
fn get_type_registration() -> TypeRegistration {
let mut registration = TypeRegistration:Cow<'static, str>>();
let mut registration = TypeRegistration::of::<Cow<'static, str>>();
registration.insert::<ReflectDeserialize>(FromType::<Cow<'static, str>>::from_type());
registration.insert::<ReflectFromPtr>(FromType::<Cow<'static, str>>::from_type());
registration.insert::<ReflectSerialize>(FromType::<Cow<'static, str>>::from_type());
registration
}
}

impl FromReflect for Cow<'static, str>c Path {
impl FromReflect for Cow<'static, str> {
fn from_reflect(reflect: &dyn crate::Reflect) -> Option<Self> {
Some(
Some(
reflect
.as_any()
.downcast_ref::<Cow<'static, str>>()?
Expand Down Expand Up @@ -1243,8 +1243,6 @@ impl Typed for &'static Path {

impl_type_path_stored!(|| TypePathStorage::new_anonymous("&std::path::Path", "&Path"), impl for &'static Path);

impl

impl GetTypeRegistration for &'static Path {
fn get_type_registration() -> TypeRegistration {
let mut registration = TypeRegistration::of::<Self>();
Expand Down Expand Up @@ -1475,4 +1473,5 @@ mod tests {
let path = Path::new("hello_world.rs");
let output = <&'static Path as FromReflect>::from_reflect(&path).unwrap();
assert_eq!(path, output);

}
}
2 changes: 1 addition & 1 deletion crates/bevy_reflect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ mod tests {
struct SomePrimitive;
impl_reflect_value!(
/// Some primitive for which we have attributed custom documentation.
SomePrimitive
SomePrimitive in bevy_reflect::tests
);

let info = <SomePrimitive as Typed>::type_info();
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_sprite/src/mesh2d/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ use crate::{
/// ```
/// # use bevy_sprite::{Material2d, MaterialMesh2dBundle};
/// # use bevy_ecs::prelude::*;
/// # use bevy_reflect::TypeUuid;
/// # use bevy_reflect::{TypeUuid, TypePath};
/// # use bevy_render::{render_resource::{AsBindGroup, ShaderRef}, texture::Image, color::Color};
/// # use bevy_asset::{Handle, AssetServer, Assets};
///
/// #[derive(AsBindGroup, TypeUuid, Debug, Clone)]
/// #[derive(AsBindGroup, TypeUuid, TypePath, Debug, Clone)]
/// #[uuid = "f690fdae-d598-45ab-8225-97e2a3f056e0"]
/// pub struct CustomMaterial {
/// // Uniform bindings must implement `ShaderType`, which will be used to convert the value to
Expand Down
4 changes: 2 additions & 2 deletions examples/3d/skybox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy::{
input::mouse::MouseMotion,
pbr::{MaterialPipeline, MaterialPipelineKey},
prelude::*,
reflect::TypeUuid,
reflect::{TypePath, TypeUuid},
render::{
mesh::MeshVertexBufferLayout,
render_asset::RenderAssets,
Expand Down Expand Up @@ -196,7 +196,7 @@ fn animate_light_direction(
}
}

#[derive(Debug, Clone, TypeUuid)]
#[derive(Debug, Clone, TypeUuid, TypePath)]
#[uuid = "9509a0f8-3c05-48ee-a13e-a93226c7f488"]
struct CubemapMaterial {
base_color_texture: Option<Handle<Image>>,
Expand Down

0 comments on commit b011a37

Please sign in to comment.