aboutsummaryrefslogtreecommitdiff
path: root/src/descriptor_set/collection.rs
blob: 77eb4faa7529f95bb45b992679cf91450f8e3f5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2016 The vulkano developers
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>,
// at your option. All files in the project carrying such
// notice may not be copied, modified, or distributed except
// according to those terms.

use crate::descriptor_set::DescriptorSetWithOffsets;

/// A collection of descriptor set objects.
pub unsafe trait DescriptorSetsCollection {
    fn into_vec(self) -> Vec<DescriptorSetWithOffsets>;
}

unsafe impl DescriptorSetsCollection for () {
    #[inline]
    fn into_vec(self) -> Vec<DescriptorSetWithOffsets> {
        vec![]
    }
}

unsafe impl<T> DescriptorSetsCollection for T
where
    T: Into<DescriptorSetWithOffsets>,
{
    fn into_vec(self) -> Vec<DescriptorSetWithOffsets> {
        vec![self.into()]
    }
}

unsafe impl<T> DescriptorSetsCollection for Vec<T>
where
    T: Into<DescriptorSetWithOffsets>,
{
    fn into_vec(self) -> Vec<DescriptorSetWithOffsets> {
        self.into_iter().map(|x| x.into()).collect()
    }
}

macro_rules! impl_collection {
    ($first:ident $(, $others:ident)+) => (
        unsafe impl<$first$(, $others)+> DescriptorSetsCollection for ($first, $($others),+)
            where $first: Into<DescriptorSetWithOffsets>
                  $(, $others: Into<DescriptorSetWithOffsets>)*
        {
            #[inline]
            #[allow(non_snake_case)]
            fn into_vec(self) -> Vec<DescriptorSetWithOffsets> {
                let ($first, $($others,)*) = self;
                vec![$first.into() $(, $others.into())+]
            }
        }

        impl_collection!($($others),+);
    );

    ($i:ident) => ();
}

impl_collection!(Z, Y, X, W, V, U, T, S, R, Q, P, O, N, M, L, K, J, I, H, G, F, E, D, C, B, A);