diff --git a/vulkano/autogen/extensions.rs b/vulkano/autogen/extensions.rs index 66a781a0..953e5681 100644 --- a/vulkano/autogen/extensions.rs +++ b/vulkano/autogen/extensions.rs @@ -338,6 +338,13 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) -> } }); + let arr_items = members.iter().map(|ExtensionsMember { name, raw, .. }| { + quote! { + (#raw, self.#name), + } + }); + let arr_len = members.len(); + let from_str_for_extensions_items = members.iter().map(|ExtensionsMember { name, raw, .. }| { let raw = Literal::string(raw); @@ -540,6 +547,16 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) -> data } } + + impl IntoIterator for #struct_name { + type Item = (&'static str, bool); + type IntoIter = std::array::IntoIter; + + #[inline] + fn into_iter(self) -> Self::IntoIter { + [#(#arr_items)*].into_iter() + } + } } } diff --git a/vulkano/autogen/features.rs b/vulkano/autogen/features.rs index 6ae9837e..ec8105d7 100644 --- a/vulkano/autogen/features.rs +++ b/vulkano/autogen/features.rs @@ -216,6 +216,13 @@ fn features_output(members: &[FeaturesMember]) -> TokenStream { } }); + let arr_items = members.iter().map(|FeaturesMember { name, raw, .. }| { + quote! { + (#raw, self.#name), + } + }); + let arr_len = members.len(); + let write_items = members.iter().map( |FeaturesMember { name, @@ -508,6 +515,15 @@ fn features_output(members: &[FeaturesMember]) -> TokenStream { } } + impl IntoIterator for Features { + type Item = (&'static str, bool); + type IntoIter = std::array::IntoIter; + + #[inline] + fn into_iter(self) -> Self::IntoIter { + [#(#arr_items)*].into_iter() + } + } } } diff --git a/vulkano/src/device/extensions.rs b/vulkano/src/device/extensions.rs index 124c1c7e..a4b29c1d 100644 --- a/vulkano/src/device/extensions.rs +++ b/vulkano/src/device/extensions.rs @@ -22,4 +22,19 @@ mod tests { let d: Vec = (&DeviceExtensions::empty()).into(); assert!(d.get(0).is_none()); } + + #[test] + fn into_iter() { + let extensions = DeviceExtensions { + khr_swapchain: true, + ..DeviceExtensions::empty() + }; + for (name, enabled) in extensions { + if name == "VK_KHR_swapchain" { + assert!(enabled); + } else { + assert!(!enabled); + } + } + } } diff --git a/vulkano/src/device/features.rs b/vulkano/src/device/features.rs index 4a210fa1..592ce3b7 100644 --- a/vulkano/src/device/features.rs +++ b/vulkano/src/device/features.rs @@ -66,3 +66,23 @@ impl Display for FeatureRestriction { } } } + +#[cfg(test)] +mod tests { + use super::Features; + + #[test] + fn into_iter() { + let features = Features { + tessellation_shader: true, + ..Features::empty() + }; + for (name, enabled) in features { + if name == "tessellationShader" { + assert!(enabled); + } else { + assert!(!enabled); + } + } + } +} diff --git a/vulkano/src/instance/extensions.rs b/vulkano/src/instance/extensions.rs index 6be3a644..3aac8447 100644 --- a/vulkano/src/instance/extensions.rs +++ b/vulkano/src/instance/extensions.rs @@ -22,4 +22,19 @@ mod tests { let i: Vec = (&InstanceExtensions::empty()).into(); assert!(i.get(0).is_none()); } + + #[test] + fn into_iter() { + let extensions = InstanceExtensions { + khr_display: true, + ..InstanceExtensions::empty() + }; + for (name, enabled) in extensions { + if name == "VK_KHR_display" { + assert!(enabled); + } else { + assert!(!enabled); + } + } + } }