From 7e3515e6eb34cd1b4b6cff872c1d0e89ff4347d5 Mon Sep 17 00:00:00 2001 From: marc0246 <40955683+marc0246@users.noreply.github.com> Date: Tue, 4 Oct 2022 10:06:36 +0200 Subject: [PATCH] Replace generics with `impl Trait` (#2017) --- vulkano-shaders/src/codegen.rs | 9 +- .../src/command_buffer/commands/bind_push.rs | 14 ++- .../command_buffer/commands/dynamic_state.rs | 88 +++++++++---------- .../src/command_buffer/commands/secondary.rs | 10 +-- vulkano/src/command_buffer/pool/sys.rs | 8 +- vulkano/src/descriptor_set/mod.rs | 14 +-- vulkano/src/descriptor_set/pool/sys.rs | 8 +- vulkano/src/image/view.rs | 5 +- vulkano/src/library.rs | 15 +--- vulkano/src/pipeline/cache.rs | 8 +- vulkano/src/sampler/mod.rs | 9 +- 11 files changed, 82 insertions(+), 106 deletions(-) diff --git a/vulkano-shaders/src/codegen.rs b/vulkano-shaders/src/codegen.rs index 3d98723e..b5345401 100644 --- a/vulkano-shaders/src/codegen.rs +++ b/vulkano-shaders/src/codegen.rs @@ -205,17 +205,14 @@ pub fn compile( Ok((content, includes)) } -pub(super) fn reflect<'a, I>( +pub(super) fn reflect<'a>( prefix: &'a str, words: &[u32], types_meta: &TypesMeta, - input_paths: I, + input_paths: impl IntoIterator, shared_constants: bool, types_registry: &'a mut HashMap, -) -> Result<(TokenStream, TokenStream), Error> -where - I: IntoIterator, -{ +) -> Result<(TokenStream, TokenStream), Error> { let spirv = Spirv::new(words)?; let include_bytes = input_paths.into_iter().map(|s| { diff --git a/vulkano/src/command_buffer/commands/bind_push.rs b/vulkano/src/command_buffer/commands/bind_push.rs index 13fe748f..bb6e3711 100644 --- a/vulkano/src/command_buffer/commands/bind_push.rs +++ b/vulkano/src/command_buffer/commands/bind_push.rs @@ -323,10 +323,11 @@ impl AutoCommandBufferBuilder { /// - Panics if `self` and any element of `vertex_buffers` do not belong to the same device. /// - Panics if any element of `vertex_buffers` does not have the /// [`vertex_buffer`](crate::buffer::BufferUsage::vertex_buffer) usage enabled. - pub fn bind_vertex_buffers(&mut self, first_binding: u32, vertex_buffers: V) -> &mut Self - where - V: VertexBuffersCollection, - { + pub fn bind_vertex_buffers( + &mut self, + first_binding: u32, + vertex_buffers: impl VertexBuffersCollection, + ) -> &mut Self { let vertex_buffers = vertex_buffers.into_vec(); self.validate_bind_vertex_buffers(first_binding, &vertex_buffers) .unwrap(); @@ -838,10 +839,7 @@ pub struct SyncCommandBufferBuilderBindDescriptorSets<'b> { impl<'b> SyncCommandBufferBuilderBindDescriptorSets<'b> { /// Adds a descriptor set to the list. #[inline] - pub fn add(&mut self, descriptor_set: S) - where - S: Into, - { + pub fn add(&mut self, descriptor_set: impl Into) { self.descriptor_sets.push(descriptor_set.into()); } diff --git a/vulkano/src/command_buffer/commands/dynamic_state.rs b/vulkano/src/command_buffer/commands/dynamic_state.rs index bcb7a9ba..40c1b5c9 100644 --- a/vulkano/src/command_buffer/commands/dynamic_state.rs +++ b/vulkano/src/command_buffer/commands/dynamic_state.rs @@ -571,10 +571,11 @@ impl AutoCommandBufferBuilder { /// - Panics if the highest discard rectangle slot being set is greater than the /// [`max_discard_rectangles`](crate::device::Properties::max_discard_rectangles) device /// property. - pub fn set_discard_rectangle(&mut self, first_rectangle: u32, rectangles: I) -> &mut Self - where - I: IntoIterator, - { + pub fn set_discard_rectangle( + &mut self, + first_rectangle: u32, + rectangles: impl IntoIterator, + ) -> &mut Self { let rectangles: SmallVec<[Scissor; 2]> = rectangles.into_iter().collect(); self.validate_set_discard_rectangle(first_rectangle, &rectangles) .unwrap(); @@ -1101,10 +1102,11 @@ impl AutoCommandBufferBuilder { /// [`max_viewports`](crate::device::Properties::max_viewports) device property. /// - If the [`multi_viewport`](crate::device::Features::multi_viewport) feature is not enabled, /// panics if `first_scissor` is not 0, or if more than 1 scissor is provided. - pub fn set_scissor(&mut self, first_scissor: u32, scissors: I) -> &mut Self - where - I: IntoIterator, - { + pub fn set_scissor( + &mut self, + first_scissor: u32, + scissors: impl IntoIterator, + ) -> &mut Self { let scissors: SmallVec<[Scissor; 2]> = scissors.into_iter().collect(); self.validate_set_scissor(first_scissor, &scissors).unwrap(); @@ -1180,10 +1182,10 @@ impl AutoCommandBufferBuilder { /// - If the [`multi_viewport`](crate::device::Features::multi_viewport) feature is not enabled, /// panics if more than 1 scissor is provided. #[inline] - pub fn set_scissor_with_count(&mut self, scissors: I) -> &mut Self - where - I: IntoIterator, - { + pub fn set_scissor_with_count( + &mut self, + scissors: impl IntoIterator, + ) -> &mut Self { let scissors: SmallVec<[Scissor; 2]> = scissors.into_iter().collect(); self.validate_set_scissor_with_count(&scissors).unwrap(); @@ -1493,10 +1495,11 @@ impl AutoCommandBufferBuilder { /// [`max_viewports`](crate::device::Properties::max_viewports) device property. /// - If the [`multi_viewport`](crate::device::Features::multi_viewport) feature is not enabled, /// panics if `first_viewport` is not 0, or if more than 1 viewport is provided. - pub fn set_viewport(&mut self, first_viewport: u32, viewports: I) -> &mut Self - where - I: IntoIterator, - { + pub fn set_viewport( + &mut self, + first_viewport: u32, + viewports: impl IntoIterator, + ) -> &mut Self { let viewports: SmallVec<[Viewport; 2]> = viewports.into_iter().collect(); self.validate_set_viewport(first_viewport, &viewports) .unwrap(); @@ -1573,10 +1576,10 @@ impl AutoCommandBufferBuilder { /// - If the [`multi_viewport`](crate::device::Features::multi_viewport) feature is not enabled, /// panics if more than 1 viewport is provided. #[inline] - pub fn set_viewport_with_count(&mut self, viewports: I) -> &mut Self - where - I: IntoIterator, - { + pub fn set_viewport_with_count( + &mut self, + viewports: impl IntoIterator, + ) -> &mut Self { let viewports: SmallVec<[Viewport; 2]> = viewports.into_iter().collect(); self.validate_set_viewport_with_count(&viewports).unwrap(); @@ -1663,10 +1666,7 @@ impl SyncCommandBufferBuilder { /// /// If the list is empty then the command is automatically ignored. #[inline] - pub unsafe fn set_color_write_enable(&mut self, enables: I) - where - I: IntoIterator, - { + pub unsafe fn set_color_write_enable(&mut self, enables: impl IntoIterator) { struct Cmd { enables: Mutex>, } @@ -1875,10 +1875,11 @@ impl SyncCommandBufferBuilder { /// /// If the list is empty then the command is automatically ignored. #[inline] - pub unsafe fn set_discard_rectangle(&mut self, first_rectangle: u32, rectangles: I) - where - I: IntoIterator, - { + pub unsafe fn set_discard_rectangle( + &mut self, + first_rectangle: u32, + rectangles: impl IntoIterator, + ) { struct Cmd { first_rectangle: u32, rectangles: Mutex>, @@ -2260,10 +2261,11 @@ impl SyncCommandBufferBuilder { /// /// If the list is empty then the command is automatically ignored. #[inline] - pub unsafe fn set_scissor(&mut self, first_scissor: u32, scissors: I) - where - I: IntoIterator, - { + pub unsafe fn set_scissor( + &mut self, + first_scissor: u32, + scissors: impl IntoIterator, + ) { struct Cmd { first_scissor: u32, scissors: Mutex>, @@ -2296,10 +2298,7 @@ impl SyncCommandBufferBuilder { /// /// If the list is empty then the command is automatically ignored. #[inline] - pub unsafe fn set_scissor_with_count(&mut self, scissors: I) - where - I: IntoIterator, - { + pub unsafe fn set_scissor_with_count(&mut self, scissors: impl IntoIterator) { struct Cmd { scissors: Mutex>, } @@ -2325,10 +2324,11 @@ impl SyncCommandBufferBuilder { /// /// If the list is empty then the command is automatically ignored. #[inline] - pub unsafe fn set_viewport(&mut self, first_viewport: u32, viewports: I) - where - I: IntoIterator, - { + pub unsafe fn set_viewport( + &mut self, + first_viewport: u32, + viewports: impl IntoIterator, + ) { struct Cmd { first_viewport: u32, viewports: Mutex>, @@ -2361,10 +2361,10 @@ impl SyncCommandBufferBuilder { /// /// If the list is empty then the command is automatically ignored. #[inline] - pub unsafe fn set_viewport_with_count(&mut self, viewports: I) - where - I: IntoIterator, - { + pub unsafe fn set_viewport_with_count( + &mut self, + viewports: impl IntoIterator, + ) { struct Cmd { viewports: Mutex>, } diff --git a/vulkano/src/command_buffer/commands/secondary.rs b/vulkano/src/command_buffer/commands/secondary.rs index 66008cd3..6af9e354 100644 --- a/vulkano/src/command_buffer/commands/secondary.rs +++ b/vulkano/src/command_buffer/commands/secondary.rs @@ -412,10 +412,7 @@ pub struct SyncCommandBufferBuilderExecuteCommands<'a> { impl<'a> SyncCommandBufferBuilderExecuteCommands<'a> { /// Adds a command buffer to the list. #[inline] - pub fn add(&mut self, command_buffer: C) - where - C: SecondaryCommandBuffer + 'static, - { + pub fn add(&mut self, command_buffer: impl SecondaryCommandBuffer + 'static) { self.inner.push(Box::new(command_buffer)); } @@ -545,10 +542,7 @@ impl UnsafeCommandBufferBuilderExecuteCommands { /// Adds a command buffer to the list. #[inline] - pub fn add(&mut self, cb: &C) - where - C: ?Sized + SecondaryCommandBuffer, - { + pub fn add(&mut self, cb: &(impl SecondaryCommandBuffer + ?Sized)) { // TODO: debug assert that it is a secondary command buffer? self.raw_cbs.push(cb.inner().internal_object()); } diff --git a/vulkano/src/command_buffer/pool/sys.rs b/vulkano/src/command_buffer/pool/sys.rs index f0f1f6df..05b55d19 100644 --- a/vulkano/src/command_buffer/pool/sys.rs +++ b/vulkano/src/command_buffer/pool/sys.rs @@ -244,10 +244,10 @@ impl UnsafeCommandPool { /// /// - The `command_buffers` must have been allocated from this pool. /// - The `command_buffers` must not be in the pending state. - pub unsafe fn free_command_buffers(&self, command_buffers: I) - where - I: IntoIterator, - { + pub unsafe fn free_command_buffers( + &self, + command_buffers: impl IntoIterator, + ) { let command_buffers: SmallVec<[_; 4]> = command_buffers.into_iter().map(|cb| cb.handle).collect(); let fns = self.device.fns(); diff --git a/vulkano/src/descriptor_set/mod.rs b/vulkano/src/descriptor_set/mod.rs index 0d3cf779..d25e5037 100644 --- a/vulkano/src/descriptor_set/mod.rs +++ b/vulkano/src/descriptor_set/mod.rs @@ -118,10 +118,12 @@ pub unsafe trait DescriptorSet: DeviceOwned + Send + Sync { fn layout(&self) -> &Arc; /// Creates a [`DescriptorSetWithOffsets`] with the given dynamic offsets. - fn offsets(self: Arc, dynamic_offsets: I) -> DescriptorSetWithOffsets + fn offsets( + self: Arc, + dynamic_offsets: impl IntoIterator, + ) -> DescriptorSetWithOffsets where Self: Sized + 'static, - I: IntoIterator, { DescriptorSetWithOffsets::new(self, dynamic_offsets) } @@ -405,10 +407,10 @@ pub struct DescriptorSetWithOffsets { impl DescriptorSetWithOffsets { #[inline] - pub fn new(descriptor_set: Arc, dynamic_offsets: O) -> Self - where - O: IntoIterator, - { + pub fn new( + descriptor_set: Arc, + dynamic_offsets: impl IntoIterator, + ) -> Self { let dynamic_offsets: SmallVec<_> = dynamic_offsets.into_iter().collect(); let layout = descriptor_set.layout(); let properties = layout.device().physical_device().properties(); diff --git a/vulkano/src/descriptor_set/pool/sys.rs b/vulkano/src/descriptor_set/pool/sys.rs index fbe20a56..75a187b8 100644 --- a/vulkano/src/descriptor_set/pool/sys.rs +++ b/vulkano/src/descriptor_set/pool/sys.rs @@ -282,10 +282,10 @@ impl UnsafeDescriptorPool { /// - The descriptor sets must not be free'd twice. /// - The descriptor sets must not be in use by the GPU. /// - pub unsafe fn free_descriptor_sets(&mut self, descriptor_sets: I) -> Result<(), OomError> - where - I: IntoIterator, - { + pub unsafe fn free_descriptor_sets( + &mut self, + descriptor_sets: impl IntoIterator, + ) -> Result<(), OomError> { let sets: SmallVec<[_; 8]> = descriptor_sets .into_iter() .map(|s| s.internal_object()) diff --git a/vulkano/src/image/view.rs b/vulkano/src/image/view.rs index 5562a2c3..fa8451c1 100644 --- a/vulkano/src/image/view.rs +++ b/vulkano/src/image/view.rs @@ -859,10 +859,7 @@ impl ImageViewCreateInfo { /// Returns an `ImageViewCreateInfo` with the `view_type` determined from the image type and /// array layers, and `subresource_range` determined from the image format and covering the /// whole image. - pub fn from_image(image: &I) -> Self - where - I: ImageAccess + ?Sized, - { + pub fn from_image(image: &(impl ImageAccess + ?Sized)) -> Self { Self { view_type: match image.dimensions() { ImageDimensions::Dim1d { diff --git a/vulkano/src/library.rs b/vulkano/src/library.rs index 526ac7ff..819e195b 100644 --- a/vulkano/src/library.rs +++ b/vulkano/src/library.rs @@ -84,10 +84,7 @@ impl VulkanLibrary { } /// Loads a custom Vulkan library. - pub fn with_loader(loader: L) -> Result, LoadingError> - where - L: Loader + 'static, - { + pub fn with_loader(loader: impl Loader + 'static) -> Result, LoadingError> { let fns = EntryFunctions::load(|name| unsafe { loader .get_instance_proc_addr(ash::vk::Instance::null(), name.as_ptr()) @@ -110,10 +107,7 @@ impl VulkanLibrary { })) } - unsafe fn get_api_version(loader: &L) -> Result - where - L: Loader, - { + unsafe fn get_api_version(loader: &impl Loader) -> Result { // Per the Vulkan spec: // If the vkGetInstanceProcAddr returns NULL for vkEnumerateInstanceVersion, it is a // Vulkan 1.0 implementation. Otherwise, the application can call vkEnumerateInstanceVersion @@ -352,10 +346,7 @@ impl DynamicLibraryLoader { /// /// - The dynamic library must be a valid Vulkan implementation. /// - pub unsafe fn new

(path: P) -> Result - where - P: AsRef, - { + pub unsafe fn new(path: impl AsRef) -> Result { let vk_lib = Library::new(path.as_ref()).map_err(LoadingError::LibraryLoadFailure)?; let get_instance_proc_addr = *vk_lib diff --git a/vulkano/src/pipeline/cache.rs b/vulkano/src/pipeline/cache.rs index b7baedd2..b26b2af6 100644 --- a/vulkano/src/pipeline/cache.rs +++ b/vulkano/src/pipeline/cache.rs @@ -141,10 +141,10 @@ impl PipelineCache { /// // FIXME: vkMergePipelineCaches is not thread safe for the destination cache // TODO: write example - pub fn merge<'a, I>(&self, pipelines: I) -> Result<(), OomError> - where - I: IntoIterator>, - { + pub fn merge<'a>( + &self, + pipelines: impl IntoIterator>, + ) -> Result<(), OomError> { unsafe { let fns = self.device.fns(); diff --git a/vulkano/src/sampler/mod.rs b/vulkano/src/sampler/mod.rs index a5aff990..02943f9c 100644 --- a/vulkano/src/sampler/mod.rs +++ b/vulkano/src/sampler/mod.rs @@ -492,13 +492,10 @@ impl Sampler { } /// Checks whether this sampler is compatible with `image_view`. - pub fn check_can_sample( + pub fn check_can_sample( &self, - image_view: &I, - ) -> Result<(), SamplerImageViewIncompatibleError> - where - I: ImageViewAbstract + ?Sized, - { + image_view: &(impl ImageViewAbstract + ?Sized), + ) -> Result<(), SamplerImageViewIncompatibleError> { /* Note: Most of these checks come from the Instruction/Sampler/Image View Validation section, and are not strictly VUIDs.