1048: Make VertexFormat::size a const fn r=kvark a=Imberflur

**Connections**
Addresses #836 

**Description**
The `vertex_attr_array!` macro uses this function. This change enables the macro to be used in `const` contexts and for instance allows returning a `VertexBufferDescriptor` constructed in function without having the difficulties of ensuring the array from `vertex_attr_array!` lives long enough.

**Testing**
I don't believe testing is needed for this.
<!--
Non-trivial functional changes would need to be tested through:
  - [wgpu-rs](https://github.com/gfx-rs/wgpu-rs) - test the examples.
  - [wgpu-native](https://github.com/gfx-rs/wgpu-native/) - check the generated C header for sanity.

Ideally, a PR needs to link to the draft PRs in these projects with relevant modifications.
See https://github.com/gfx-rs/wgpu/pull/666 for an example.
If you can add a unit/integration test here in `wgpu`, that would be best.
-->


Co-authored-by: Imbris <imbrisf@gmail.com>
This commit is contained in:
bors[bot] 2020-11-26 18:06:21 +00:00 committed by GitHub
commit 75b46976a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1165,7 +1165,7 @@ pub enum VertexFormat {
}
impl VertexFormat {
pub fn size(&self) -> u64 {
pub const fn size(&self) -> u64 {
match self {
Self::Uchar2 | Self::Char2 | Self::Uchar2Norm | Self::Char2Norm => 2,
Self::Uchar4