quickgpu/builders/
command_encoder_descriptor_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::CommandEncoderDescriptor`]\n "]
9pub struct CommandEncoderDescriptorBuilder<'a, CS: State<'a>> {
10 label: CS::Label,
11}
12impl<'a> CommandEncoderDescriptorBuilder<'a, Empty> {
13 pub fn new() -> CommandEncoderDescriptorBuilder<'a, Empty> {
14 CommandEncoderDescriptorBuilder { label: LabelEmpty }
15 }
16}
17#[doc = "\nReturns [CommandEncoderDescriptorBuilder] for building [`wgpu::CommandEncoderDescriptor`]\n "]
18pub fn command_encoder_descriptor<'a>(
19 label: wgpu::Label<'a>,
20) -> CommandEncoderDescriptorBuilder<'a, SetLabel<Empty>> {
21 CommandEncoderDescriptorBuilder::new().label(label)
22}
23pub struct LabelEmpty;
24impl Field for LabelEmpty {}
25pub trait LabelIsEmpty {}
26impl LabelIsEmpty for LabelEmpty {}
27pub trait IsSetLabel<'a> {
28 fn get(self) -> wgpu::Label<'a>;
29}
30impl<'a> IsSetLabel<'a> for LabelEmpty {
31 fn get(self) -> wgpu::Label<'a> {
32 None
33 }
34}
35pub struct LabelValue<'a>(pub wgpu::Label<'a>);
36impl<'a> Field for LabelValue<'a> {}
37impl<'a> IsSetLabel<'a> for LabelValue<'a> {
38 fn get(self) -> wgpu::Label<'a> {
39 self.0
40 }
41}
42pub trait State<'a> {
43 type Label: Field;
44}
45pub struct Empty;
46impl<'a> State<'a> for Empty {
47 type Label = LabelEmpty;
48}
49pub struct SetLabel<CS>(CS);
50impl<'a, CS: State<'a>> State<'a> for SetLabel<CS> {
51 type Label = LabelValue<'a>;
52}
53impl<'a, CS: State<'a>> CommandEncoderDescriptorBuilder<'a, CS> {
54 #[doc = "Setter for [wgpu::CommandEncoderDescriptor::label]. Optional, defaults to `None`.\n"]
55 pub fn label(self, label: wgpu::Label<'a>) -> CommandEncoderDescriptorBuilder<'a, SetLabel<CS>>
56 where
57 CS::Label: LabelIsEmpty,
58 {
59 CommandEncoderDescriptorBuilder {
60 label: LabelValue(label),
61 }
62 }
63}
64pub trait Complete<'a>: State<'a, Label: IsSetLabel<'a>> {}
65impl<'a, CS: State<'a, Label: IsSetLabel<'a>>> Complete<'a> for CS {}
66impl<'a, CS: Complete<'a>> CommandEncoderDescriptorBuilder<'a, CS> {
67 pub fn build(self) -> wgpu::CommandEncoderDescriptor<'a> {
68 wgpu::CommandEncoderDescriptor {
69 label: IsSetLabel::get(self.label),
70 }
71 }
72}
73#[cfg(test)]
74mod tests {
75 #[allow(unused_imports)]
76 #[allow(unused_imports)]
77 use std::num::NonZeroU32;
78 #[test]
79 pub fn test_default() {
80 assert_eq!(
81 format!(
82 "{:#?}",
83 super::command_encoder_descriptor(Option::<&str>::None).build()
84 ),
85 format!("{:#?}", wgpu::CommandEncoderDescriptor::default()),
86 );
87 }
88}