wgpu_types/
markers.rs

1/// Marker trait used to determine which types uniquely identify a resource.
2///
3/// For example, `Device<A>` will have the same type of identifier as
4/// `Device<B>` because `Device<T>` for any `T` defines the same maker type.
5pub trait Marker: 'static + crate::WasmNotSendSync {
6    const TYPE: &'static str;
7}
8
9// This allows `()` to be used as a marker type for tests.
10//
11// We don't want these in production code, since they essentially remove type
12// safety, like how identifiers across different types can be compared.
13#[cfg(test)]
14impl Marker for () {
15    const TYPE: &'static str = "Untyped";
16}
17
18/// Define markers for each resource.
19macro_rules! ids {
20    ($(
21        $(#[$($meta:meta)*])*
22        pub type $marker:ident;
23    )*) => {
24        /// Marker types for each resource.
25        pub mod markers {
26            $(
27                #[derive(Debug)]
28                pub enum $marker {}
29                impl super::Marker for $marker {
30                    const TYPE: &'static str = stringify!($marker);
31                }
32            )*
33        }
34    }
35}
36
37ids! {
38    pub type Adapter;
39    pub type Surface;
40    pub type Device;
41    pub type Queue;
42    pub type Buffer;
43    pub type StagingBuffer;
44    pub type TextureView;
45    pub type Texture;
46    pub type ExternalTexture;
47    pub type Sampler;
48    pub type BindGroupLayout;
49    pub type PipelineLayout;
50    pub type BindGroup;
51    pub type ShaderModule;
52    pub type RenderPipeline;
53    pub type ComputePipeline;
54    pub type PipelineCache;
55    pub type CommandEncoder;
56    pub type CommandBuffer;
57    pub type RenderPassEncoder;
58    pub type ComputePassEncoder;
59    pub type RenderBundleEncoder;
60    pub type RenderBundle;
61    pub type QuerySet;
62    pub type Blas;
63    pub type Tlas;
64}