1 // Copyright (c) 2016 The vulkano developers 2 // Licensed under the Apache License, Version 2.0 3 // <LICENSE-APACHE or 4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT 5 // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, 6 // at your option. All files in the project carrying such 7 // notice may not be copied, modified, or distributed except 8 // according to those terms. 9 10 use crate::descriptor_set::DescriptorSetWithOffsets; 11 12 /// A collection of descriptor set objects. 13 pub unsafe trait DescriptorSetsCollection { into_vec(self) -> Vec<DescriptorSetWithOffsets>14 fn into_vec(self) -> Vec<DescriptorSetWithOffsets>; 15 } 16 17 unsafe impl DescriptorSetsCollection for () { 18 #[inline] into_vec(self) -> Vec<DescriptorSetWithOffsets>19 fn into_vec(self) -> Vec<DescriptorSetWithOffsets> { 20 vec![] 21 } 22 } 23 24 unsafe impl<T> DescriptorSetsCollection for T 25 where 26 T: Into<DescriptorSetWithOffsets>, 27 { into_vec(self) -> Vec<DescriptorSetWithOffsets>28 fn into_vec(self) -> Vec<DescriptorSetWithOffsets> { 29 vec![self.into()] 30 } 31 } 32 33 unsafe impl<T> DescriptorSetsCollection for Vec<T> 34 where 35 T: Into<DescriptorSetWithOffsets>, 36 { into_vec(self) -> Vec<DescriptorSetWithOffsets>37 fn into_vec(self) -> Vec<DescriptorSetWithOffsets> { 38 self.into_iter().map(|x| x.into()).collect() 39 } 40 } 41 42 macro_rules! impl_collection { 43 ($first:ident $(, $others:ident)+) => ( 44 unsafe impl<$first$(, $others)+> DescriptorSetsCollection for ($first, $($others),+) 45 where $first: Into<DescriptorSetWithOffsets> 46 $(, $others: Into<DescriptorSetWithOffsets>)* 47 { 48 #[inline] 49 #[allow(non_snake_case)] 50 fn into_vec(self) -> Vec<DescriptorSetWithOffsets> { 51 let ($first, $($others,)*) = self; 52 vec![$first.into() $(, $others.into())+] 53 } 54 } 55 56 impl_collection!($($others),+); 57 ); 58 59 ($i:ident) => (); 60 } 61 62 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); 63