1pub use super::super::Nested;
5pub use std::{borrow::Cow, num::NonZeroU32, ops::Range};
6pub trait Field {}
7pub trait IsOptional {}
8#[doc = "\nBuilder for [`wgpu::VertexState`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [module](VertexStateBuilder::module) Required\n - [entry_point](VertexStateBuilder::entry_point) Optional, defaults to `None`\n - [compilation_options](VertexStateBuilder::compilation_options) Optional, defaults to [wgpu::PipelineCompilationOptions::default()]\n - [buffers](VertexStateBuilder::buffers) Required\n"]
9pub struct VertexStateBuilder<'a, CS: State<'a>> {
10 module: CS::Module,
11 entry_point: CS::EntryPoint,
12 compilation_options: CS::CompilationOptions,
13 buffers: CS::Buffers,
14}
15impl<'a> VertexStateBuilder<'a, Empty> {
16 pub fn new() -> VertexStateBuilder<'a, Empty> {
17 VertexStateBuilder {
18 module: ModuleEmpty,
19 entry_point: EntryPointEmpty,
20 compilation_options: CompilationOptionsEmpty,
21 buffers: BuffersEmpty,
22 }
23 }
24}
25#[doc = "\nReturns [VertexStateBuilder] for building [`wgpu::VertexState`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [module](VertexStateBuilder::module) Required\n - [entry_point](VertexStateBuilder::entry_point) Optional, defaults to `None`\n - [compilation_options](VertexStateBuilder::compilation_options) Optional, defaults to [wgpu::PipelineCompilationOptions::default()]\n - [buffers](VertexStateBuilder::buffers) Required\n"]
26pub fn vertex_state<'a>() -> VertexStateBuilder<'a, Empty> {
27 VertexStateBuilder::new()
28}
29pub struct ModuleEmpty;
30impl Field for ModuleEmpty {}
31pub trait ModuleIsEmpty {}
32impl ModuleIsEmpty for ModuleEmpty {}
33pub trait IsSetModule<'a> {
34 fn get(self) -> &'a wgpu::ShaderModule;
35}
36pub struct ModuleValue<'a>(pub &'a wgpu::ShaderModule);
37impl<'a> Field for ModuleValue<'a> {}
38impl<'a> IsSetModule<'a> for ModuleValue<'a> {
39 fn get(self) -> &'a wgpu::ShaderModule {
40 self.0
41 }
42}
43pub struct EntryPointEmpty;
44impl Field for EntryPointEmpty {}
45pub trait EntryPointIsEmpty {}
46impl EntryPointIsEmpty for EntryPointEmpty {}
47pub trait IsSetEntryPoint<'a> {
48 fn get(self) -> Option<&'a str>;
49}
50impl<'a> IsSetEntryPoint<'a> for EntryPointEmpty {
51 fn get(self) -> Option<&'a str> {
52 None
53 }
54}
55pub struct EntryPointValue<'a>(pub Option<&'a str>);
56impl<'a> Field for EntryPointValue<'a> {}
57impl<'a> IsSetEntryPoint<'a> for EntryPointValue<'a> {
58 fn get(self) -> Option<&'a str> {
59 self.0
60 }
61}
62pub struct CompilationOptionsEmpty;
63impl Field for CompilationOptionsEmpty {}
64pub trait CompilationOptionsIsEmpty {}
65impl CompilationOptionsIsEmpty for CompilationOptionsEmpty {}
66pub trait IsSetCompilationOptions<'a> {
67 fn get(self) -> wgpu::PipelineCompilationOptions<'a>;
68}
69impl<'a> IsSetCompilationOptions<'a> for CompilationOptionsEmpty {
70 fn get(self) -> wgpu::PipelineCompilationOptions<'a> {
71 wgpu::PipelineCompilationOptions::default()
72 }
73}
74pub struct CompilationOptionsValue<'a>(pub wgpu::PipelineCompilationOptions<'a>);
75impl<'a> Field for CompilationOptionsValue<'a> {}
76impl<'a> IsSetCompilationOptions<'a> for CompilationOptionsValue<'a> {
77 fn get(self) -> wgpu::PipelineCompilationOptions<'a> {
78 self.0
79 }
80}
81pub struct BuffersEmpty;
82impl Field for BuffersEmpty {}
83pub trait BuffersIsEmpty {}
84impl BuffersIsEmpty for BuffersEmpty {}
85pub trait IsSetBuffers<'a> {
86 fn get(self) -> &'a [wgpu::VertexBufferLayout<'a>];
87}
88pub struct BuffersValue<'a>(pub &'a [wgpu::VertexBufferLayout<'a>]);
89impl<'a> Field for BuffersValue<'a> {}
90impl<'a> IsSetBuffers<'a> for BuffersValue<'a> {
91 fn get(self) -> &'a [wgpu::VertexBufferLayout<'a>] {
92 self.0
93 }
94}
95pub trait State<'a> {
96 type Module: Field;
97 type EntryPoint: Field;
98 type CompilationOptions: Field;
99 type Buffers: Field;
100}
101pub struct Empty;
102impl<'a> State<'a> for Empty {
103 type Module = ModuleEmpty;
104 type EntryPoint = EntryPointEmpty;
105 type CompilationOptions = CompilationOptionsEmpty;
106 type Buffers = BuffersEmpty;
107}
108pub struct SetModule<CS>(CS);
109impl<'a, CS: State<'a>> State<'a> for SetModule<CS> {
110 type Module = ModuleValue<'a>;
111 type EntryPoint = CS::EntryPoint;
112 type CompilationOptions = CS::CompilationOptions;
113 type Buffers = CS::Buffers;
114}
115pub struct SetEntryPoint<CS>(CS);
116impl<'a, CS: State<'a>> State<'a> for SetEntryPoint<CS> {
117 type Module = CS::Module;
118 type EntryPoint = EntryPointValue<'a>;
119 type CompilationOptions = CS::CompilationOptions;
120 type Buffers = CS::Buffers;
121}
122pub struct SetCompilationOptions<CS>(CS);
123impl<'a, CS: State<'a>> State<'a> for SetCompilationOptions<CS> {
124 type Module = CS::Module;
125 type EntryPoint = CS::EntryPoint;
126 type CompilationOptions = CompilationOptionsValue<'a>;
127 type Buffers = CS::Buffers;
128}
129pub struct SetBuffers<CS>(CS);
130impl<'a, CS: State<'a>> State<'a> for SetBuffers<CS> {
131 type Module = CS::Module;
132 type EntryPoint = CS::EntryPoint;
133 type CompilationOptions = CS::CompilationOptions;
134 type Buffers = BuffersValue<'a>;
135}
136impl<'a, CS: State<'a>> VertexStateBuilder<'a, CS> {
137 #[doc = "Setter for [wgpu::VertexState::module]. Required.\n"]
138 pub fn module(self, module: &'a wgpu::ShaderModule) -> VertexStateBuilder<'a, SetModule<CS>>
139 where
140 CS::Module: ModuleIsEmpty,
141 {
142 VertexStateBuilder {
143 module: ModuleValue(module),
144 entry_point: self.entry_point,
145 compilation_options: self.compilation_options,
146 buffers: self.buffers,
147 }
148 }
149 #[doc = "Setter for [wgpu::VertexState::entry_point]. Optional, defaults to `None`.\n"]
150 pub fn entry_point(self, entry_point: &'a str) -> VertexStateBuilder<'a, SetEntryPoint<CS>>
151 where
152 CS::EntryPoint: EntryPointIsEmpty,
153 {
154 VertexStateBuilder {
155 module: self.module,
156 entry_point: EntryPointValue(Some(entry_point)),
157 compilation_options: self.compilation_options,
158 buffers: self.buffers,
159 }
160 }
161 #[doc = "Setter for [wgpu::VertexState::entry_point]. Optional, defaults to `None`.\n"]
162 pub fn maybe_entry_point(
163 self,
164 entry_point: Option<&'a str>,
165 ) -> VertexStateBuilder<'a, SetEntryPoint<CS>>
166 where
167 CS::EntryPoint: EntryPointIsEmpty,
168 {
169 VertexStateBuilder {
170 module: self.module,
171 entry_point: EntryPointValue(entry_point),
172 compilation_options: self.compilation_options,
173 buffers: self.buffers,
174 }
175 }
176 #[doc = "Setter for [wgpu::VertexState::compilation_options]. Optional, defaults to [wgpu::PipelineCompilationOptions::default()].\n"]
177 pub fn compilation_options(
178 self,
179 compilation_options: impl Nested<wgpu::PipelineCompilationOptions<'a>>,
180 ) -> VertexStateBuilder<'a, SetCompilationOptions<CS>>
181 where
182 CS::CompilationOptions: CompilationOptionsIsEmpty,
183 {
184 VertexStateBuilder {
185 module: self.module,
186 entry_point: self.entry_point,
187 compilation_options: CompilationOptionsValue(Nested::unnest(compilation_options)),
188 buffers: self.buffers,
189 }
190 }
191 #[doc = "Setter for [wgpu::VertexState::buffers]. Required.\n"]
192 pub fn buffers(
193 self,
194 buffers: &'a [wgpu::VertexBufferLayout<'a>],
195 ) -> VertexStateBuilder<'a, SetBuffers<CS>>
196 where
197 CS::Buffers: BuffersIsEmpty,
198 {
199 VertexStateBuilder {
200 module: self.module,
201 entry_point: self.entry_point,
202 compilation_options: self.compilation_options,
203 buffers: BuffersValue(buffers),
204 }
205 }
206}
207pub trait Complete<'a>:
208 State<
209 'a,
210 Module: IsSetModule<'a>,
211 EntryPoint: IsSetEntryPoint<'a>,
212 CompilationOptions: IsSetCompilationOptions<'a>,
213 Buffers: IsSetBuffers<'a>,
214>
215{
216}
217impl<
218 'a,
219 CS: State<
220 'a,
221 Module: IsSetModule<'a>,
222 EntryPoint: IsSetEntryPoint<'a>,
223 CompilationOptions: IsSetCompilationOptions<'a>,
224 Buffers: IsSetBuffers<'a>,
225 >,
226 > Complete<'a> for CS
227{
228}
229impl<'a, CS: Complete<'a>> VertexStateBuilder<'a, CS> {
230 pub fn build(self) -> wgpu::VertexState<'a> {
231 wgpu::VertexState {
232 module: IsSetModule::get(self.module),
233 entry_point: IsSetEntryPoint::get(self.entry_point),
234 compilation_options: IsSetCompilationOptions::get(self.compilation_options),
235 buffers: IsSetBuffers::get(self.buffers),
236 }
237 }
238}
239impl<'a> Nested<wgpu::VertexState<'a>> for wgpu::VertexState<'a> {
240 fn unnest(self) -> wgpu::VertexState<'a> {
241 self
242 }
243}
244impl<'a, CS: Complete<'a>> Nested<wgpu::VertexState<'a>> for VertexStateBuilder<'a, CS> {
245 fn unnest(self) -> wgpu::VertexState<'a> {
246 self.build()
247 }
248}
249#[cfg(test)]
250mod tests {
251 #[allow(unused_imports)]
252 #[allow(unused_imports)]
253 use std::num::NonZeroU32;
254 #[test]
255 pub fn test_default() {
256 assert_eq!(
257 format!("{:#?}", super::IsSetEntryPoint::get(super::EntryPointEmpty)),
258 format!("{:#?}", Option::<&str>::default()),
259 );
260 assert_eq!(
261 format!(
262 "{:#?}",
263 super::IsSetCompilationOptions::get(super::CompilationOptionsEmpty)
264 ),
265 format!("{:#?}", wgpu::PipelineCompilationOptions::default()),
266 );
267 }
268}