1#![cfg_attr(not(feature = "std"), no_std)]
2#![doc = include_str!("../README.md")]
3#![expect(non_snake_case)]
4#![expect(non_upper_case_globals)]
5
6include!("../generated/bindings.rs");
7include!("../generated/lib.rs");
8
9impl WGPUStringView {
12 pub fn null() -> Self {
13 Self {
14 data: core::ptr::null(),
15 length: WGPU_STRLEN,
16 }
17 }
18
19 pub fn empty() -> Self {
20 Self {
21 data: core::ptr::null(),
22 length: 0,
23 }
24 }
25
26 pub fn from_bytes<'a, T: Into<Option<&'a [u8]>>>(bytes: T) -> Self {
27 if let Some(bytes) = bytes.into() {
28 Self {
29 data:
30 bytes.as_ptr().cast(),
31 length:
32 bytes.len(),
33 }
34 } else {
35 Self::null()
36 }
37 }
38
39 #[expect(clippy::should_implement_trait, reason = "WGPUStringView::from_str never fails")]
40 pub fn from_str<'a, T: Into<Option<&'a str>>>(s: T) -> Self {
41 Self::from_bytes(s.into().map(str::as_bytes))
42 }
43
44 pub fn as_bytes(&self) -> &[u8] {
45 if self.length == 0 || self.data.is_null() {
46 &[]
47 } else if self.length == WGPU_STRLEN {
48 unsafe {
49 core::ffi::CStr::from_ptr(self.data.cast())
50 }.to_bytes()
51 } else {
52 unsafe {
53 core::slice::from_raw_parts(
54 self.data.cast(),
55 self.length)
56 }
57 }
58 }
59
60 #[cfg(feature = "std")]
61 pub fn to_string_lossy(&self) -> String {
62 String::from_utf8_lossy(self.as_bytes()).into_owned()
63 }
64}
65
66pub const WGPU_TRUE: WGPUBool = 1;
68
69pub const WGPU_FALSE: WGPUBool = 0;
71
72pub const WGPU_ARRAY_LAYER_COUNT_UNDEFINED: u32 = u32::MAX;
74
75pub const WGPU_COPY_STRIDE_UNDEFINED: u32 = u32::MAX;
77
78pub const WGPU_DEPTH_CLEAR_VALUE_UNDEFINED: f32 = f32::NAN;
80
81pub const WGPU_DEPTH_SLICE_UNDEFINED: u32 = u32::MAX;
83
84pub const WGPU_LIMIT_U32_UNDEFINED: u32 = u32::MAX;
86
87pub const WGPU_LIMIT_U64_UNDEFINED: u64 = u64::MAX;
89
90pub const WGPU_MIP_LEVEL_COUNT_UNDEFINED: u32 = u32::MAX;
92
93pub const WGPU_QUERY_SET_INDEX_UNDEFINED: u32 = u32::MAX;
95
96pub const WGPU_STRLEN: usize = usize::MAX;
98
99pub const WGPU_WHOLE_MAP_SIZE: usize = usize::MAX;
101
102pub const WGPU_WHOLE_SIZE: u64 = u64::MAX;