dawn_sys/
lib.rs

1#![no_std]
2#![doc = include_str!("../README.md")]
3#![expect(non_upper_case_globals)]
4
5mod raw {
6    #![expect(dead_code)]
7    #![expect(non_camel_case_types)]
8    #![expect(non_snake_case)]
9
10    include!("../generated/bindings.rs");
11    include!("../generated/bitmasks.rs");
12}
13
14include!("../generated/lib.rs");
15
16/// `true` value of [`WGPUBool`].
17pub const WGPU_TRUE: WGPUBool = 1;
18
19/// `false` value of [`WGPUBool`].
20pub const WGPU_FALSE: WGPUBool = 0;
21
22/// Indicates no array layer count is specified.
23pub const WGPU_ARRAY_LAYER_COUNT_UNDEFINED: u32 = u32::MAX;
24
25/// Indicates no copy stride is specified.
26pub const WGPU_COPY_STRIDE_UNDEFINED: u32 = u32::MAX;
27
28/// Indicates no depth clear value is specified.
29pub const WGPU_DEPTH_CLEAR_VALUE_UNDEFINED: f32 = f32::NAN;
30
31/// Indicates no depth slice is specified.
32pub const WGPU_DEPTH_SLICE_UNDEFINED: u32 = u32::MAX;
33
34/// For `u32` limits, indicates no limit value is specified.
35pub const WGPU_LIMIT_U32_UNDEFINED: u32 = u32::MAX;
36
37/// For `u64` limits, indicates no limit value is specified.
38pub const WGPU_LIMIT_U64_UNDEFINED: u64 = u64::MAX;
39
40/// Indicates no mip level count is specified.
41pub const WGPU_MIP_LEVEL_COUNT_UNDEFINED: u32 = u32::MAX;
42
43/// Indicates no query set index is specified.
44pub const WGPU_QUERY_SET_INDEX_UNDEFINED: u32 = u32::MAX;
45
46/// Sentinel value used in [`WGPUStringView`].
47pub const WGPU_STRLEN: usize = usize::MAX;
48
49/// Indicates a size extending to the end of the buffer.
50pub const WGPU_WHOLE_MAP_SIZE: usize = usize::MAX;
51
52/// Indicates a size extending to the end of the buffer.
53pub const WGPU_WHOLE_SIZE: u64 = u64::MAX;
54
55impl WGPUStringView {
56    /// The *null* value of [`WGPUStringView`], as is specified in [WebGPU Headers: Strings](https://webgpu-native.github.io/webgpu-headers/Strings.html).
57    /// 
58    /// Note that this is distinct from [`WGPUStringView::empty`], and
59    /// is not considered as an empty string.
60    pub fn null() -> Self {
61        Self {
62            data: core::ptr::null(),
63            length: WGPU_STRLEN,
64        }
65    }
66
67    /// The empty string, as is specified in [WebGPU Headers: Strings](https://webgpu-native.github.io/webgpu-headers/Strings.html).
68    /// 
69    /// Note that this is not the only valid empty string representation.
70    /// To check if a string is empty, use [`WGPUStringView::is_empty`]
71    /// instead of comparing with this value.
72    pub fn empty() -> Self {
73        Self {
74            data: core::ptr::null(),
75            length: 0,
76        }
77    }
78
79    /// Returns `true` if this string is [`WGPUStringView::null`]. `false` otherwise.
80    pub fn is_null(&self) -> bool {
81        self == &Self::null()
82    }
83
84    /// Returns `true` if this string is empty. `false` otherwise.
85    /// 
86    /// This method is equivalent to `self.length == 0`.
87    /// 
88    /// Note that [`WGPUStringView::null`] is not considered as an empty string,
89    /// as is specified in [WebGPU Headers: Strings](https://webgpu-native.github.io/webgpu-headers/Strings.html).
90    pub fn is_empty(&self) -> bool {
91        self.length == 0
92    }
93}
94
95impl From<&str> for WGPUStringView {
96    fn from(s: &str) -> Self {
97        Self {
98            data: s.as_ptr().cast(),
99            length: s.len(),
100        }
101    }
102}
103
104impl From<Option<&str>> for WGPUStringView {
105    fn from(s: Option<&str>) -> Self {
106        s.map_or(Self::null(), Self::from)
107    }
108}