quickgpu/builders/
vertex_attribute_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::VertexAttribute`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [format](VertexAttributeBuilder::format) Required\n - [offset](VertexAttributeBuilder::offset) Required\n - [shader_location](VertexAttributeBuilder::shader_location) Required\n"]
9pub struct VertexAttributeBuilder<CS: State> {
10 format: CS::Format,
11 offset: CS::Offset,
12 shader_location: CS::ShaderLocation,
13}
14impl VertexAttributeBuilder<Empty> {
15 pub fn new() -> VertexAttributeBuilder<Empty> {
16 VertexAttributeBuilder {
17 format: FormatEmpty,
18 offset: OffsetEmpty,
19 shader_location: ShaderLocationEmpty,
20 }
21 }
22}
23#[doc = "\nReturns [VertexAttributeBuilder] for building [`wgpu::VertexAttribute`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [format](VertexAttributeBuilder::format) Required\n - [offset](VertexAttributeBuilder::offset) Required\n - [shader_location](VertexAttributeBuilder::shader_location) Required\n"]
24pub fn vertex_attribute() -> VertexAttributeBuilder<Empty> {
25 VertexAttributeBuilder::new()
26}
27pub struct FormatEmpty;
28impl Field for FormatEmpty {}
29pub trait FormatIsEmpty {}
30impl FormatIsEmpty for FormatEmpty {}
31pub trait IsSetFormat {
32 fn get(self) -> wgpu::VertexFormat;
33}
34pub struct FormatValue(pub wgpu::VertexFormat);
35impl Field for FormatValue {}
36impl IsSetFormat for FormatValue {
37 fn get(self) -> wgpu::VertexFormat {
38 self.0
39 }
40}
41pub struct OffsetEmpty;
42impl Field for OffsetEmpty {}
43pub trait OffsetIsEmpty {}
44impl OffsetIsEmpty for OffsetEmpty {}
45pub trait IsSetOffset {
46 fn get(self) -> wgpu::BufferAddress;
47}
48pub struct OffsetValue(pub wgpu::BufferAddress);
49impl Field for OffsetValue {}
50impl IsSetOffset for OffsetValue {
51 fn get(self) -> wgpu::BufferAddress {
52 self.0
53 }
54}
55pub struct ShaderLocationEmpty;
56impl Field for ShaderLocationEmpty {}
57pub trait ShaderLocationIsEmpty {}
58impl ShaderLocationIsEmpty for ShaderLocationEmpty {}
59pub trait IsSetShaderLocation {
60 fn get(self) -> wgpu::ShaderLocation;
61}
62pub struct ShaderLocationValue(pub wgpu::ShaderLocation);
63impl Field for ShaderLocationValue {}
64impl IsSetShaderLocation for ShaderLocationValue {
65 fn get(self) -> wgpu::ShaderLocation {
66 self.0
67 }
68}
69pub trait State {
70 type Format: Field;
71 type Offset: Field;
72 type ShaderLocation: Field;
73}
74pub struct Empty;
75impl State for Empty {
76 type Format = FormatEmpty;
77 type Offset = OffsetEmpty;
78 type ShaderLocation = ShaderLocationEmpty;
79}
80pub struct SetFormat<CS>(CS);
81impl<CS: State> State for SetFormat<CS> {
82 type Format = FormatValue;
83 type Offset = CS::Offset;
84 type ShaderLocation = CS::ShaderLocation;
85}
86pub struct SetOffset<CS>(CS);
87impl<CS: State> State for SetOffset<CS> {
88 type Format = CS::Format;
89 type Offset = OffsetValue;
90 type ShaderLocation = CS::ShaderLocation;
91}
92pub struct SetShaderLocation<CS>(CS);
93impl<CS: State> State for SetShaderLocation<CS> {
94 type Format = CS::Format;
95 type Offset = CS::Offset;
96 type ShaderLocation = ShaderLocationValue;
97}
98impl<CS: State> VertexAttributeBuilder<CS> {
99 #[doc = "Setter for [wgpu::VertexAttribute::format]. Required.\n"]
100 pub fn format(self, format: wgpu::VertexFormat) -> VertexAttributeBuilder<SetFormat<CS>>
101 where
102 CS::Format: FormatIsEmpty,
103 {
104 VertexAttributeBuilder {
105 format: FormatValue(format),
106 offset: self.offset,
107 shader_location: self.shader_location,
108 }
109 }
110 #[doc = "Setter for [wgpu::VertexAttribute::offset]. Required.\n"]
111 pub fn offset(self, offset: wgpu::BufferAddress) -> VertexAttributeBuilder<SetOffset<CS>>
112 where
113 CS::Offset: OffsetIsEmpty,
114 {
115 VertexAttributeBuilder {
116 format: self.format,
117 offset: OffsetValue(offset),
118 shader_location: self.shader_location,
119 }
120 }
121 #[doc = "Setter for [wgpu::VertexAttribute::shader_location]. Required.\n"]
122 pub fn shader_location(
123 self,
124 shader_location: wgpu::ShaderLocation,
125 ) -> VertexAttributeBuilder<SetShaderLocation<CS>>
126 where
127 CS::ShaderLocation: ShaderLocationIsEmpty,
128 {
129 VertexAttributeBuilder {
130 format: self.format,
131 offset: self.offset,
132 shader_location: ShaderLocationValue(shader_location),
133 }
134 }
135}
136pub trait Complete:
137 State<Format: IsSetFormat, Offset: IsSetOffset, ShaderLocation: IsSetShaderLocation>
138{
139}
140impl<CS: State<Format: IsSetFormat, Offset: IsSetOffset, ShaderLocation: IsSetShaderLocation>>
141 Complete for CS
142{
143}
144impl<CS: Complete> VertexAttributeBuilder<CS> {
145 pub fn build(self) -> wgpu::VertexAttribute {
146 wgpu::VertexAttribute {
147 format: IsSetFormat::get(self.format),
148 offset: IsSetOffset::get(self.offset),
149 shader_location: IsSetShaderLocation::get(self.shader_location),
150 }
151 }
152}
153impl Nested<wgpu::VertexAttribute> for wgpu::VertexAttribute {
154 fn unnest(self) -> wgpu::VertexAttribute {
155 self
156 }
157}
158impl<CS: Complete> Nested<wgpu::VertexAttribute> for VertexAttributeBuilder<CS> {
159 fn unnest(self) -> wgpu::VertexAttribute {
160 self.build()
161 }
162}
163#[cfg(test)]
164mod tests {
165 #[allow(unused_imports)]
166 #[allow(unused_imports)]
167 use std::num::NonZeroU32;
168 #[test]
169 pub fn test_default() {}
170}