dawn_sys/
lib.rs

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
9/// See <https://webgpu-native.github.io/webgpu-headers/group__UtilityTypes.html#ga9437e366d8583db3dd6ba695a970409d>
10/// for details on [`WGPUStringView`] and the `WGPU_STRLEN` sentinel value.
11impl 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
66/// `true` value of [`WGPUBool`].
67pub const WGPU_TRUE: WGPUBool = 1;
68
69/// `false` value of [`WGPUBool`].
70pub const WGPU_FALSE: WGPUBool = 0;
71
72/// Indicates no array layer count is specified.
73pub const WGPU_ARRAY_LAYER_COUNT_UNDEFINED: u32 = u32::MAX;
74
75/// Indicates no copy stride is specified.
76pub const WGPU_COPY_STRIDE_UNDEFINED: u32 = u32::MAX;
77
78/// Indicates no depth clear value is specified.
79pub const WGPU_DEPTH_CLEAR_VALUE_UNDEFINED: f32 = f32::NAN;
80
81/// Indicates no depth slice is specified.
82pub const WGPU_DEPTH_SLICE_UNDEFINED: u32 = u32::MAX;
83
84/// For `u32` limits, indicates no limit value is specified.
85pub const WGPU_LIMIT_U32_UNDEFINED: u32 = u32::MAX;
86
87/// For `u64` limits, indicates no limit value is specified.
88pub const WGPU_LIMIT_U64_UNDEFINED: u64 = u64::MAX;
89
90/// Indicates no mip level count is specified.
91pub const WGPU_MIP_LEVEL_COUNT_UNDEFINED: u32 = u32::MAX;
92
93/// Indicates no query set index is specified.
94pub const WGPU_QUERY_SET_INDEX_UNDEFINED: u32 = u32::MAX;
95
96/// Sentinel value used in [`WGPUStringView`].
97pub const WGPU_STRLEN: usize = usize::MAX;
98
99/// Indicates a size extending to the end of the buffer.
100pub const WGPU_WHOLE_MAP_SIZE: usize = usize::MAX;
101
102/// Indicates a size extending to the end of the buffer.
103pub const WGPU_WHOLE_SIZE: u64 = u64::MAX;