quickgpu/builders/
dispatch_indirect_args_builder.rs1pub use super::super::Nested;
5pub use std::{borrow::Cow, num::NonZeroU32, ops::Range};
6pub trait Field {}
7pub trait IsOptional {}
8#[doc = "\nBuilder for [`wgpu::util::DispatchIndirectArgs`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [x](DispatchIndirectArgsBuilder::x) Optional, defaults to `0u32`\n - [y](DispatchIndirectArgsBuilder::y) Optional, defaults to `0u32`\n - [z](DispatchIndirectArgsBuilder::z) Optional, defaults to `0u32`\n"]
9pub struct DispatchIndirectArgsBuilder<CS: State> {
10 x: CS::X,
11 y: CS::Y,
12 z: CS::Z,
13}
14impl DispatchIndirectArgsBuilder<Empty> {
15 pub fn new() -> DispatchIndirectArgsBuilder<Empty> {
16 DispatchIndirectArgsBuilder {
17 x: XEmpty,
18 y: YEmpty,
19 z: ZEmpty,
20 }
21 }
22}
23#[doc = "\nReturns [DispatchIndirectArgsBuilder] for building [`wgpu::util::DispatchIndirectArgs`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [x](DispatchIndirectArgsBuilder::x) Optional, defaults to `0u32`\n - [y](DispatchIndirectArgsBuilder::y) Optional, defaults to `0u32`\n - [z](DispatchIndirectArgsBuilder::z) Optional, defaults to `0u32`\n"]
24pub fn dispatch_indirect_args() -> DispatchIndirectArgsBuilder<Empty> {
25 DispatchIndirectArgsBuilder::new()
26}
27pub struct XEmpty;
28impl Field for XEmpty {}
29pub trait XIsEmpty {}
30impl XIsEmpty for XEmpty {}
31pub trait IsSetX {
32 fn get(self) -> u32;
33}
34impl IsSetX for XEmpty {
35 fn get(self) -> u32 {
36 0u32
37 }
38}
39pub struct XValue(pub u32);
40impl Field for XValue {}
41impl IsSetX for XValue {
42 fn get(self) -> u32 {
43 self.0
44 }
45}
46pub struct YEmpty;
47impl Field for YEmpty {}
48pub trait YIsEmpty {}
49impl YIsEmpty for YEmpty {}
50pub trait IsSetY {
51 fn get(self) -> u32;
52}
53impl IsSetY for YEmpty {
54 fn get(self) -> u32 {
55 0u32
56 }
57}
58pub struct YValue(pub u32);
59impl Field for YValue {}
60impl IsSetY for YValue {
61 fn get(self) -> u32 {
62 self.0
63 }
64}
65pub struct ZEmpty;
66impl Field for ZEmpty {}
67pub trait ZIsEmpty {}
68impl ZIsEmpty for ZEmpty {}
69pub trait IsSetZ {
70 fn get(self) -> u32;
71}
72impl IsSetZ for ZEmpty {
73 fn get(self) -> u32 {
74 0u32
75 }
76}
77pub struct ZValue(pub u32);
78impl Field for ZValue {}
79impl IsSetZ for ZValue {
80 fn get(self) -> u32 {
81 self.0
82 }
83}
84pub trait State {
85 type X: Field;
86 type Y: Field;
87 type Z: Field;
88}
89pub struct Empty;
90impl State for Empty {
91 type X = XEmpty;
92 type Y = YEmpty;
93 type Z = ZEmpty;
94}
95pub struct SetX<CS>(CS);
96impl<CS: State> State for SetX<CS> {
97 type X = XValue;
98 type Y = CS::Y;
99 type Z = CS::Z;
100}
101pub struct SetY<CS>(CS);
102impl<CS: State> State for SetY<CS> {
103 type X = CS::X;
104 type Y = YValue;
105 type Z = CS::Z;
106}
107pub struct SetZ<CS>(CS);
108impl<CS: State> State for SetZ<CS> {
109 type X = CS::X;
110 type Y = CS::Y;
111 type Z = ZValue;
112}
113impl<CS: State> DispatchIndirectArgsBuilder<CS> {
114 #[doc = "Setter for [wgpu::util::DispatchIndirectArgs::x]. Optional, defaults to `0u32`.\n"]
115 pub fn x(self, x: u32) -> DispatchIndirectArgsBuilder<SetX<CS>>
116 where
117 CS::X: XIsEmpty,
118 {
119 DispatchIndirectArgsBuilder {
120 x: XValue(x),
121 y: self.y,
122 z: self.z,
123 }
124 }
125 #[doc = "Setter for [wgpu::util::DispatchIndirectArgs::y]. Optional, defaults to `0u32`.\n"]
126 pub fn y(self, y: u32) -> DispatchIndirectArgsBuilder<SetY<CS>>
127 where
128 CS::Y: YIsEmpty,
129 {
130 DispatchIndirectArgsBuilder {
131 x: self.x,
132 y: YValue(y),
133 z: self.z,
134 }
135 }
136 #[doc = "Setter for [wgpu::util::DispatchIndirectArgs::z]. Optional, defaults to `0u32`.\n"]
137 pub fn z(self, z: u32) -> DispatchIndirectArgsBuilder<SetZ<CS>>
138 where
139 CS::Z: ZIsEmpty,
140 {
141 DispatchIndirectArgsBuilder {
142 x: self.x,
143 y: self.y,
144 z: ZValue(z),
145 }
146 }
147}
148pub trait Complete: State<X: IsSetX, Y: IsSetY, Z: IsSetZ> {}
149impl<CS: State<X: IsSetX, Y: IsSetY, Z: IsSetZ>> Complete for CS {}
150impl<CS: Complete> DispatchIndirectArgsBuilder<CS> {
151 pub fn build(self) -> wgpu::util::DispatchIndirectArgs {
152 wgpu::util::DispatchIndirectArgs {
153 x: IsSetX::get(self.x),
154 y: IsSetY::get(self.y),
155 z: IsSetZ::get(self.z),
156 }
157 }
158}
159impl Nested<wgpu::util::DispatchIndirectArgs> for wgpu::util::DispatchIndirectArgs {
160 fn unnest(self) -> wgpu::util::DispatchIndirectArgs {
161 self
162 }
163}
164impl<CS: Complete> Nested<wgpu::util::DispatchIndirectArgs> for DispatchIndirectArgsBuilder<CS> {
165 fn unnest(self) -> wgpu::util::DispatchIndirectArgs {
166 self.build()
167 }
168}
169#[cfg(test)]
170mod tests {
171 #[allow(unused_imports)]
172 #[allow(unused_imports)]
173 use std::num::NonZeroU32;
174 #[test]
175 pub fn test_default() {
176 assert_eq!(
177 format!("{:#?}", super::dispatch_indirect_args().build()),
178 format!("{:#?}", wgpu::util::DispatchIndirectArgs::default()),
179 );
180 }
181}