quickgpu/builders/
extent_3_d_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::Extent3d`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [width](Extent3dBuilder::width) Optional, defaults to `1`\n - [height](Extent3dBuilder::height) Optional, defaults to `1`\n - [depth_or_array_layers](Extent3dBuilder::depth_or_array_layers) Optional, defaults to `1`\n"]
9pub struct Extent3dBuilder<CS: State> {
10 width: CS::Width,
11 height: CS::Height,
12 depth_or_array_layers: CS::DepthOrArrayLayers,
13}
14impl Extent3dBuilder<Empty> {
15 pub fn new() -> Extent3dBuilder<Empty> {
16 Extent3dBuilder {
17 width: WidthEmpty,
18 height: HeightEmpty,
19 depth_or_array_layers: DepthOrArrayLayersEmpty,
20 }
21 }
22}
23#[doc = "\nReturns [Extent3dBuilder] for building [`wgpu::Extent3d`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [width](Extent3dBuilder::width) Optional, defaults to `1`\n - [height](Extent3dBuilder::height) Optional, defaults to `1`\n - [depth_or_array_layers](Extent3dBuilder::depth_or_array_layers) Optional, defaults to `1`\n"]
24pub fn extent_3_d() -> Extent3dBuilder<Empty> {
25 Extent3dBuilder::new()
26}
27pub struct WidthEmpty;
28impl Field for WidthEmpty {}
29pub trait WidthIsEmpty {}
30impl WidthIsEmpty for WidthEmpty {}
31pub trait IsSetWidth {
32 fn get(self) -> u32;
33}
34impl IsSetWidth for WidthEmpty {
35 fn get(self) -> u32 {
36 1
37 }
38}
39pub struct WidthValue(pub u32);
40impl Field for WidthValue {}
41impl IsSetWidth for WidthValue {
42 fn get(self) -> u32 {
43 self.0
44 }
45}
46pub struct HeightEmpty;
47impl Field for HeightEmpty {}
48pub trait HeightIsEmpty {}
49impl HeightIsEmpty for HeightEmpty {}
50pub trait IsSetHeight {
51 fn get(self) -> u32;
52}
53impl IsSetHeight for HeightEmpty {
54 fn get(self) -> u32 {
55 1
56 }
57}
58pub struct HeightValue(pub u32);
59impl Field for HeightValue {}
60impl IsSetHeight for HeightValue {
61 fn get(self) -> u32 {
62 self.0
63 }
64}
65pub struct DepthOrArrayLayersEmpty;
66impl Field for DepthOrArrayLayersEmpty {}
67pub trait DepthOrArrayLayersIsEmpty {}
68impl DepthOrArrayLayersIsEmpty for DepthOrArrayLayersEmpty {}
69pub trait IsSetDepthOrArrayLayers {
70 fn get(self) -> u32;
71}
72impl IsSetDepthOrArrayLayers for DepthOrArrayLayersEmpty {
73 fn get(self) -> u32 {
74 1
75 }
76}
77pub struct DepthOrArrayLayersValue(pub u32);
78impl Field for DepthOrArrayLayersValue {}
79impl IsSetDepthOrArrayLayers for DepthOrArrayLayersValue {
80 fn get(self) -> u32 {
81 self.0
82 }
83}
84pub trait State {
85 type Width: Field;
86 type Height: Field;
87 type DepthOrArrayLayers: Field;
88}
89pub struct Empty;
90impl State for Empty {
91 type Width = WidthEmpty;
92 type Height = HeightEmpty;
93 type DepthOrArrayLayers = DepthOrArrayLayersEmpty;
94}
95pub struct SetWidth<CS>(CS);
96impl<CS: State> State for SetWidth<CS> {
97 type Width = WidthValue;
98 type Height = CS::Height;
99 type DepthOrArrayLayers = CS::DepthOrArrayLayers;
100}
101pub struct SetHeight<CS>(CS);
102impl<CS: State> State for SetHeight<CS> {
103 type Width = CS::Width;
104 type Height = HeightValue;
105 type DepthOrArrayLayers = CS::DepthOrArrayLayers;
106}
107pub struct SetDepthOrArrayLayers<CS>(CS);
108impl<CS: State> State for SetDepthOrArrayLayers<CS> {
109 type Width = CS::Width;
110 type Height = CS::Height;
111 type DepthOrArrayLayers = DepthOrArrayLayersValue;
112}
113impl<CS: State> Extent3dBuilder<CS> {
114 #[doc = "Setter for [wgpu::Extent3d::width]. Optional, defaults to `1`.\n"]
115 pub fn width(self, width: u32) -> Extent3dBuilder<SetWidth<CS>>
116 where
117 CS::Width: WidthIsEmpty,
118 {
119 Extent3dBuilder {
120 width: WidthValue(width),
121 height: self.height,
122 depth_or_array_layers: self.depth_or_array_layers,
123 }
124 }
125 #[doc = "Setter for [wgpu::Extent3d::height]. Optional, defaults to `1`.\n"]
126 pub fn height(self, height: u32) -> Extent3dBuilder<SetHeight<CS>>
127 where
128 CS::Height: HeightIsEmpty,
129 {
130 Extent3dBuilder {
131 width: self.width,
132 height: HeightValue(height),
133 depth_or_array_layers: self.depth_or_array_layers,
134 }
135 }
136 #[doc = "Setter for [wgpu::Extent3d::depth_or_array_layers]. Optional, defaults to `1`.\n"]
137 pub fn depth_or_array_layers(
138 self,
139 depth_or_array_layers: u32,
140 ) -> Extent3dBuilder<SetDepthOrArrayLayers<CS>>
141 where
142 CS::DepthOrArrayLayers: DepthOrArrayLayersIsEmpty,
143 {
144 Extent3dBuilder {
145 width: self.width,
146 height: self.height,
147 depth_or_array_layers: DepthOrArrayLayersValue(depth_or_array_layers),
148 }
149 }
150}
151pub trait Complete:
152 State<Width: IsSetWidth, Height: IsSetHeight, DepthOrArrayLayers: IsSetDepthOrArrayLayers>
153{
154}
155impl<
156 CS: State<Width: IsSetWidth, Height: IsSetHeight, DepthOrArrayLayers: IsSetDepthOrArrayLayers>,
157 > Complete for CS
158{
159}
160impl<CS: Complete> Extent3dBuilder<CS> {
161 pub fn build(self) -> wgpu::Extent3d {
162 wgpu::Extent3d {
163 width: IsSetWidth::get(self.width),
164 height: IsSetHeight::get(self.height),
165 depth_or_array_layers: IsSetDepthOrArrayLayers::get(self.depth_or_array_layers),
166 }
167 }
168}
169impl Nested<wgpu::Extent3d> for wgpu::Extent3d {
170 fn unnest(self) -> wgpu::Extent3d {
171 self
172 }
173}
174impl<CS: Complete> Nested<wgpu::Extent3d> for Extent3dBuilder<CS> {
175 fn unnest(self) -> wgpu::Extent3d {
176 self.build()
177 }
178}
179#[cfg(test)]
180mod tests {
181 #[allow(unused_imports)]
182 #[allow(unused_imports)]
183 use std::num::NonZeroU32;
184 #[test]
185 pub fn test_default() {
186 assert_eq!(
187 format!("{:#?}", super::extent_3_d().build()),
188 format!("{:#?}", wgpu::Extent3d::default()),
189 );
190 }
191}