Reflect for TextureFormat (#15355)

# Objective

In order to derive `Reflect`, all of a struct's fields must implement
`FromReflect`. [As part of looking into some of the work mentioned
here](https://github.com/bevyengine/bevy/issues/13713#issuecomment-2364786694),
I noticed that `TextureFormat` doesn't implement `Reflect`, and decided
to split that into a separate PR.

## Solution

I decided that `TextureFormat` should be a `reflect_value` since,
although one variant has fields, most users will treat this as an opaque
value set explicitly. It also substantially reduces the complexity of
the implementation.

For now, this implementation isn't actually used by any crates, so, I
decided to not preemptively enable the feature on anything. But it's
technically an option, now, and more `wgpu` types can be added in the
future.

## Testing

Everything compiles okay, and I can't really see how this could be done
incorrectly given the above constraints.
This commit is contained in:
Clar Fon 2024-09-23 13:26:12 -04:00 committed by GitHub
parent fb324f0e89
commit 2c5be2ef4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 2 deletions

View File

@ -17,6 +17,7 @@ glam = ["dep:glam"]
petgraph = ["dep:petgraph"]
smallvec = ["dep:smallvec"]
uuid = ["dep:uuid"]
wgpu-types = ["dep:wgpu-types"]
# Enables features useful for debugging reflection
debug = ["debug_stack"]
# When enabled, keeps track of the current serialization/deserialization context for better error messages
@ -44,6 +45,7 @@ glam = { version = "0.28", features = ["serde"], optional = true }
petgraph = { version = "0.6", features = ["serde-1"], optional = true }
smol_str = { version = "0.2.0", features = ["serde"], optional = true }
uuid = { version = "1.0", optional = true, features = ["v4", "serde"] }
wgpu-types = { version = "22", features = ["serde"], optional = true }
[dev-dependencies]
ron = "0.8.0"

View File

@ -0,0 +1,8 @@
use crate::{self as bevy_reflect, impl_reflect_value, ReflectDeserialize, ReflectSerialize};
impl_reflect_value!(::wgpu_types::TextureFormat(
Debug,
Hash,
PartialEq,
Deserialize,
Serialize,
));

View File

@ -562,6 +562,8 @@ mod type_path;
mod type_registry;
mod impls {
mod std;
#[cfg(feature = "glam")]
mod glam;
#[cfg(feature = "petgraph")]
@ -570,10 +572,10 @@ mod impls {
mod smallvec;
#[cfg(feature = "smol_str")]
mod smol_str;
mod std;
#[cfg(feature = "uuid")]
mod uuid;
#[cfg(feature = "wgpu-types")]
mod wgpu_types;
}
pub mod attributes;