-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - Added TryFrom for VertexAttributeValues #1963
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like splitting this out into a conversions.rs file! And seems like helpful functionality with great tests.
Thanks |
You should |
Yes, I completely agree, I will do it now, thank you |
- `Short2` - `Short2Norm` - `Ushort2` - `Ushort2Norm` - `Short4` - `Short4Norm` - `Ushort4` - `Ushort4Norm` - `Char2` - `Char2Norm` - `Uchar2` - `Uchar2Norm` - `Char4` - `Char4Norm` - `Uchar4`
Can you change the PR name? It'll get squashed down into a single commit with that name when we merge and it's now backwards :) |
VertexAttributeValues::Uchar2Norm(..) => "VertexAttributeValues::Uchar2Norm", | ||
VertexAttributeValues::Char4(..) => "VertexAttributeValues::Char4", | ||
VertexAttributeValues::Char4Norm(..) => "VertexAttributeValues::Char4Norm", | ||
VertexAttributeValues::Uchar4(..) => "VertexAttributeValues::Uchar4", | ||
VertexAttributeValues::Uchar4Norm(..) => "VertexAttributeValues::Uchar4Norm", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not added a _
placeholder so that whoever adds new formats will take care of conversions
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: MinerSebas <66798382+MinerSebas@users.noreply.github.com>
Looks good to me! I moved the tests into their own submodule to ensure imports aren't unused when building without tests. I'd also like to remove the manual "type name strings" everywhere. But I understand that rust doesn't give us the tools we need to get enum variant names. We could use a crate like For now, lets just merge this! |
bors r+ |
This implementations allows you convert std::vec::Vec<T> to VertexAttributeValues::T and back. # Examples ```rust use std::convert::TryInto; use bevy_render::mesh::VertexAttributeValues; // creating vector of values let before = vec![[0_u32; 4]; 10]; let values = VertexAttributeValues::from(before.clone()); let after: Vec<[u32; 4]> = values.try_into().unwrap(); assert_eq!(before, after); ``` Co-authored-by: aloucks <aloucks@cofront.net> Co-authored-by: simens_green <34134129+simensgreen@users.noreply.github.com> Co-authored-by: Carter Anderson <mcanders1@gmail.com>
Build failed: |
bors r+ |
This implementations allows you convert std::vec::Vec<T> to VertexAttributeValues::T and back. # Examples ```rust use std::convert::TryInto; use bevy_render::mesh::VertexAttributeValues; // creating vector of values let before = vec![[0_u32; 4]; 10]; let values = VertexAttributeValues::from(before.clone()); let after: Vec<[u32; 4]> = values.try_into().unwrap(); assert_eq!(before, after); ``` Co-authored-by: aloucks <aloucks@cofront.net> Co-authored-by: simens_green <34134129+simensgreen@users.noreply.github.com> Co-authored-by: Carter Anderson <mcanders1@gmail.com>
Pull request successfully merged into main. Build succeeded: |
There are cases where we want an enum variant name. Right now the only way to do that with rust's std is to derive Debug, but this will also print out the variant's fields. This creates the unfortunate situation where we need to manually write out each variant's string name (ex: in #1963), which is both boilerplate-ey and error-prone. Crates such as `strum` exist for this reason, but it includes a lot of code and complexity that we don't need. This adds a dead-simple `EnumVariantMeta` derive that exposes `enum_variant_index` and `enum_variant_name` functions. This allows us to make cases like #1963 much cleaner (see the second commit). We might also be able to reuse this logic for `bevy_reflect` enum derives.
This implementations allows you convert std::vec::Vec<T> to VertexAttributeValues::T and back. # Examples ```rust use std::convert::TryInto; use bevy_render::mesh::VertexAttributeValues; // creating vector of values let before = vec![[0_u32; 4]; 10]; let values = VertexAttributeValues::from(before.clone()); let after: Vec<[u32; 4]> = values.try_into().unwrap(); assert_eq!(before, after); ``` Co-authored-by: aloucks <aloucks@cofront.net> Co-authored-by: simens_green <34134129+simensgreen@users.noreply.github.com> Co-authored-by: Carter Anderson <mcanders1@gmail.com>
There are cases where we want an enum variant name. Right now the only way to do that with rust's std is to derive Debug, but this will also print out the variant's fields. This creates the unfortunate situation where we need to manually write out each variant's string name (ex: in bevyengine#1963), which is both boilerplate-ey and error-prone. Crates such as `strum` exist for this reason, but it includes a lot of code and complexity that we don't need. This adds a dead-simple `EnumVariantMeta` derive that exposes `enum_variant_index` and `enum_variant_name` functions. This allows us to make cases like bevyengine#1963 much cleaner (see the second commit). We might also be able to reuse this logic for `bevy_reflect` enum derives.
This implementations allows you
convert std::vec::Vec to VertexAttributeValues::T and back.
Examples