Skip to content

Commit 04a62fe

Browse files
refactor: add wgpu_types::size module
1 parent 013ed87 commit 04a62fe

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

wgpu-types/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ mod render;
4444
#[doc(hidden)] // without this we get spurious missing_docs warnings
4545
mod send_sync;
4646
mod shader;
47+
pub mod size;
4748
mod surface;
4849
mod texture;
4950
mod tokens;

wgpu-types/src/size.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//! Utilities for converting between [`usize`]s and fixed-size integrals in wgpu, mostly
2+
//! [`usize_from_u32`].
3+
//!
4+
//! wgpu crates only support 32-bit targets. This module both enforces this at compile time, and
5+
//! offers conveniences for converting between [`u32`] and [`usize`] that [`core`] cannot provide,
6+
//! because Rust's minimum assumed word size is 16 bits.
7+
8+
/// This is the load-bearing constant type assertion for the rest of the module. If this is true,
9+
/// then everything else should Just Work™.
10+
const _: () = assert!(
11+
size_of::<usize>() >= size_of::<u32>(),
12+
"word sizes < 32 bits are not supported in wgpu crates"
13+
);
14+
15+
/// Convert a [`u32`] to a [`usize`].
16+
pub const fn usize_from_u32(n: u32) -> usize {
17+
n as usize
18+
}

0 commit comments

Comments
 (0)