Replace generics with impl Trait (#2017)

This commit is contained in:
marc0246 2022-10-04 10:06:36 +02:00 committed by GitHub
parent 1c2d195dab
commit 7e3515e6eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 82 additions and 106 deletions

View File

@ -205,17 +205,14 @@ pub fn compile(
Ok((content, includes)) Ok((content, includes))
} }
pub(super) fn reflect<'a, I>( pub(super) fn reflect<'a>(
prefix: &'a str, prefix: &'a str,
words: &[u32], words: &[u32],
types_meta: &TypesMeta, types_meta: &TypesMeta,
input_paths: I, input_paths: impl IntoIterator<Item = &'a str>,
shared_constants: bool, shared_constants: bool,
types_registry: &'a mut HashMap<String, RegisteredType>, types_registry: &'a mut HashMap<String, RegisteredType>,
) -> Result<(TokenStream, TokenStream), Error> ) -> Result<(TokenStream, TokenStream), Error> {
where
I: IntoIterator<Item = &'a str>,
{
let spirv = Spirv::new(words)?; let spirv = Spirv::new(words)?;
let include_bytes = input_paths.into_iter().map(|s| { let include_bytes = input_paths.into_iter().map(|s| {

View File

@ -323,10 +323,11 @@ impl<L, P> AutoCommandBufferBuilder<L, P> {
/// - Panics if `self` and any element of `vertex_buffers` do not belong to the same device. /// - 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 /// - Panics if any element of `vertex_buffers` does not have the
/// [`vertex_buffer`](crate::buffer::BufferUsage::vertex_buffer) usage enabled. /// [`vertex_buffer`](crate::buffer::BufferUsage::vertex_buffer) usage enabled.
pub fn bind_vertex_buffers<V>(&mut self, first_binding: u32, vertex_buffers: V) -> &mut Self pub fn bind_vertex_buffers(
where &mut self,
V: VertexBuffersCollection, first_binding: u32,
{ vertex_buffers: impl VertexBuffersCollection,
) -> &mut Self {
let vertex_buffers = vertex_buffers.into_vec(); let vertex_buffers = vertex_buffers.into_vec();
self.validate_bind_vertex_buffers(first_binding, &vertex_buffers) self.validate_bind_vertex_buffers(first_binding, &vertex_buffers)
.unwrap(); .unwrap();
@ -838,10 +839,7 @@ pub struct SyncCommandBufferBuilderBindDescriptorSets<'b> {
impl<'b> SyncCommandBufferBuilderBindDescriptorSets<'b> { impl<'b> SyncCommandBufferBuilderBindDescriptorSets<'b> {
/// Adds a descriptor set to the list. /// Adds a descriptor set to the list.
#[inline] #[inline]
pub fn add<S>(&mut self, descriptor_set: S) pub fn add(&mut self, descriptor_set: impl Into<DescriptorSetWithOffsets>) {
where
S: Into<DescriptorSetWithOffsets>,
{
self.descriptor_sets.push(descriptor_set.into()); self.descriptor_sets.push(descriptor_set.into());
} }

View File

@ -571,10 +571,11 @@ impl<L, P> AutoCommandBufferBuilder<L, P> {
/// - Panics if the highest discard rectangle slot being set is greater than the /// - Panics if the highest discard rectangle slot being set is greater than the
/// [`max_discard_rectangles`](crate::device::Properties::max_discard_rectangles) device /// [`max_discard_rectangles`](crate::device::Properties::max_discard_rectangles) device
/// property. /// property.
pub fn set_discard_rectangle<I>(&mut self, first_rectangle: u32, rectangles: I) -> &mut Self pub fn set_discard_rectangle(
where &mut self,
I: IntoIterator<Item = Scissor>, first_rectangle: u32,
{ rectangles: impl IntoIterator<Item = Scissor>,
) -> &mut Self {
let rectangles: SmallVec<[Scissor; 2]> = rectangles.into_iter().collect(); let rectangles: SmallVec<[Scissor; 2]> = rectangles.into_iter().collect();
self.validate_set_discard_rectangle(first_rectangle, &rectangles) self.validate_set_discard_rectangle(first_rectangle, &rectangles)
.unwrap(); .unwrap();
@ -1101,10 +1102,11 @@ impl<L, P> AutoCommandBufferBuilder<L, P> {
/// [`max_viewports`](crate::device::Properties::max_viewports) device property. /// [`max_viewports`](crate::device::Properties::max_viewports) device property.
/// - If the [`multi_viewport`](crate::device::Features::multi_viewport) feature is not enabled, /// - 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. /// panics if `first_scissor` is not 0, or if more than 1 scissor is provided.
pub fn set_scissor<I>(&mut self, first_scissor: u32, scissors: I) -> &mut Self pub fn set_scissor(
where &mut self,
I: IntoIterator<Item = Scissor>, first_scissor: u32,
{ scissors: impl IntoIterator<Item = Scissor>,
) -> &mut Self {
let scissors: SmallVec<[Scissor; 2]> = scissors.into_iter().collect(); let scissors: SmallVec<[Scissor; 2]> = scissors.into_iter().collect();
self.validate_set_scissor(first_scissor, &scissors).unwrap(); self.validate_set_scissor(first_scissor, &scissors).unwrap();
@ -1180,10 +1182,10 @@ impl<L, P> AutoCommandBufferBuilder<L, P> {
/// - If the [`multi_viewport`](crate::device::Features::multi_viewport) feature is not enabled, /// - If the [`multi_viewport`](crate::device::Features::multi_viewport) feature is not enabled,
/// panics if more than 1 scissor is provided. /// panics if more than 1 scissor is provided.
#[inline] #[inline]
pub fn set_scissor_with_count<I>(&mut self, scissors: I) -> &mut Self pub fn set_scissor_with_count(
where &mut self,
I: IntoIterator<Item = Scissor>, scissors: impl IntoIterator<Item = Scissor>,
{ ) -> &mut Self {
let scissors: SmallVec<[Scissor; 2]> = scissors.into_iter().collect(); let scissors: SmallVec<[Scissor; 2]> = scissors.into_iter().collect();
self.validate_set_scissor_with_count(&scissors).unwrap(); self.validate_set_scissor_with_count(&scissors).unwrap();
@ -1493,10 +1495,11 @@ impl<L, P> AutoCommandBufferBuilder<L, P> {
/// [`max_viewports`](crate::device::Properties::max_viewports) device property. /// [`max_viewports`](crate::device::Properties::max_viewports) device property.
/// - If the [`multi_viewport`](crate::device::Features::multi_viewport) feature is not enabled, /// - 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. /// panics if `first_viewport` is not 0, or if more than 1 viewport is provided.
pub fn set_viewport<I>(&mut self, first_viewport: u32, viewports: I) -> &mut Self pub fn set_viewport(
where &mut self,
I: IntoIterator<Item = Viewport>, first_viewport: u32,
{ viewports: impl IntoIterator<Item = Viewport>,
) -> &mut Self {
let viewports: SmallVec<[Viewport; 2]> = viewports.into_iter().collect(); let viewports: SmallVec<[Viewport; 2]> = viewports.into_iter().collect();
self.validate_set_viewport(first_viewport, &viewports) self.validate_set_viewport(first_viewport, &viewports)
.unwrap(); .unwrap();
@ -1573,10 +1576,10 @@ impl<L, P> AutoCommandBufferBuilder<L, P> {
/// - If the [`multi_viewport`](crate::device::Features::multi_viewport) feature is not enabled, /// - If the [`multi_viewport`](crate::device::Features::multi_viewport) feature is not enabled,
/// panics if more than 1 viewport is provided. /// panics if more than 1 viewport is provided.
#[inline] #[inline]
pub fn set_viewport_with_count<I>(&mut self, viewports: I) -> &mut Self pub fn set_viewport_with_count(
where &mut self,
I: IntoIterator<Item = Viewport>, viewports: impl IntoIterator<Item = Viewport>,
{ ) -> &mut Self {
let viewports: SmallVec<[Viewport; 2]> = viewports.into_iter().collect(); let viewports: SmallVec<[Viewport; 2]> = viewports.into_iter().collect();
self.validate_set_viewport_with_count(&viewports).unwrap(); 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. /// If the list is empty then the command is automatically ignored.
#[inline] #[inline]
pub unsafe fn set_color_write_enable<I>(&mut self, enables: I) pub unsafe fn set_color_write_enable(&mut self, enables: impl IntoIterator<Item = bool>) {
where
I: IntoIterator<Item = bool>,
{
struct Cmd<I> { struct Cmd<I> {
enables: Mutex<Option<I>>, enables: Mutex<Option<I>>,
} }
@ -1875,10 +1875,11 @@ impl SyncCommandBufferBuilder {
/// ///
/// If the list is empty then the command is automatically ignored. /// If the list is empty then the command is automatically ignored.
#[inline] #[inline]
pub unsafe fn set_discard_rectangle<I>(&mut self, first_rectangle: u32, rectangles: I) pub unsafe fn set_discard_rectangle(
where &mut self,
I: IntoIterator<Item = Scissor>, first_rectangle: u32,
{ rectangles: impl IntoIterator<Item = Scissor>,
) {
struct Cmd { struct Cmd {
first_rectangle: u32, first_rectangle: u32,
rectangles: Mutex<SmallVec<[Scissor; 2]>>, rectangles: Mutex<SmallVec<[Scissor; 2]>>,
@ -2260,10 +2261,11 @@ impl SyncCommandBufferBuilder {
/// ///
/// If the list is empty then the command is automatically ignored. /// If the list is empty then the command is automatically ignored.
#[inline] #[inline]
pub unsafe fn set_scissor<I>(&mut self, first_scissor: u32, scissors: I) pub unsafe fn set_scissor(
where &mut self,
I: IntoIterator<Item = Scissor>, first_scissor: u32,
{ scissors: impl IntoIterator<Item = Scissor>,
) {
struct Cmd { struct Cmd {
first_scissor: u32, first_scissor: u32,
scissors: Mutex<SmallVec<[Scissor; 2]>>, scissors: Mutex<SmallVec<[Scissor; 2]>>,
@ -2296,10 +2298,7 @@ impl SyncCommandBufferBuilder {
/// ///
/// If the list is empty then the command is automatically ignored. /// If the list is empty then the command is automatically ignored.
#[inline] #[inline]
pub unsafe fn set_scissor_with_count<I>(&mut self, scissors: I) pub unsafe fn set_scissor_with_count(&mut self, scissors: impl IntoIterator<Item = Scissor>) {
where
I: IntoIterator<Item = Scissor>,
{
struct Cmd { struct Cmd {
scissors: Mutex<SmallVec<[Scissor; 2]>>, scissors: Mutex<SmallVec<[Scissor; 2]>>,
} }
@ -2325,10 +2324,11 @@ impl SyncCommandBufferBuilder {
/// ///
/// If the list is empty then the command is automatically ignored. /// If the list is empty then the command is automatically ignored.
#[inline] #[inline]
pub unsafe fn set_viewport<I>(&mut self, first_viewport: u32, viewports: I) pub unsafe fn set_viewport(
where &mut self,
I: IntoIterator<Item = Viewport>, first_viewport: u32,
{ viewports: impl IntoIterator<Item = Viewport>,
) {
struct Cmd { struct Cmd {
first_viewport: u32, first_viewport: u32,
viewports: Mutex<SmallVec<[Viewport; 2]>>, viewports: Mutex<SmallVec<[Viewport; 2]>>,
@ -2361,10 +2361,10 @@ impl SyncCommandBufferBuilder {
/// ///
/// If the list is empty then the command is automatically ignored. /// If the list is empty then the command is automatically ignored.
#[inline] #[inline]
pub unsafe fn set_viewport_with_count<I>(&mut self, viewports: I) pub unsafe fn set_viewport_with_count(
where &mut self,
I: IntoIterator<Item = Viewport>, viewports: impl IntoIterator<Item = Viewport>,
{ ) {
struct Cmd { struct Cmd {
viewports: Mutex<SmallVec<[Viewport; 2]>>, viewports: Mutex<SmallVec<[Viewport; 2]>>,
} }

View File

@ -412,10 +412,7 @@ pub struct SyncCommandBufferBuilderExecuteCommands<'a> {
impl<'a> SyncCommandBufferBuilderExecuteCommands<'a> { impl<'a> SyncCommandBufferBuilderExecuteCommands<'a> {
/// Adds a command buffer to the list. /// Adds a command buffer to the list.
#[inline] #[inline]
pub fn add<C>(&mut self, command_buffer: C) pub fn add(&mut self, command_buffer: impl SecondaryCommandBuffer + 'static) {
where
C: SecondaryCommandBuffer + 'static,
{
self.inner.push(Box::new(command_buffer)); self.inner.push(Box::new(command_buffer));
} }
@ -545,10 +542,7 @@ impl UnsafeCommandBufferBuilderExecuteCommands {
/// Adds a command buffer to the list. /// Adds a command buffer to the list.
#[inline] #[inline]
pub fn add<C>(&mut self, cb: &C) pub fn add(&mut self, cb: &(impl SecondaryCommandBuffer + ?Sized)) {
where
C: ?Sized + SecondaryCommandBuffer,
{
// TODO: debug assert that it is a secondary command buffer? // TODO: debug assert that it is a secondary command buffer?
self.raw_cbs.push(cb.inner().internal_object()); self.raw_cbs.push(cb.inner().internal_object());
} }

View File

@ -244,10 +244,10 @@ impl UnsafeCommandPool {
/// ///
/// - The `command_buffers` must have been allocated from this pool. /// - The `command_buffers` must have been allocated from this pool.
/// - The `command_buffers` must not be in the pending state. /// - The `command_buffers` must not be in the pending state.
pub unsafe fn free_command_buffers<I>(&self, command_buffers: I) pub unsafe fn free_command_buffers(
where &self,
I: IntoIterator<Item = UnsafeCommandPoolAlloc>, command_buffers: impl IntoIterator<Item = UnsafeCommandPoolAlloc>,
{ ) {
let command_buffers: SmallVec<[_; 4]> = let command_buffers: SmallVec<[_; 4]> =
command_buffers.into_iter().map(|cb| cb.handle).collect(); command_buffers.into_iter().map(|cb| cb.handle).collect();
let fns = self.device.fns(); let fns = self.device.fns();

View File

@ -118,10 +118,12 @@ pub unsafe trait DescriptorSet: DeviceOwned + Send + Sync {
fn layout(&self) -> &Arc<DescriptorSetLayout>; fn layout(&self) -> &Arc<DescriptorSetLayout>;
/// Creates a [`DescriptorSetWithOffsets`] with the given dynamic offsets. /// Creates a [`DescriptorSetWithOffsets`] with the given dynamic offsets.
fn offsets<I>(self: Arc<Self>, dynamic_offsets: I) -> DescriptorSetWithOffsets fn offsets(
self: Arc<Self>,
dynamic_offsets: impl IntoIterator<Item = u32>,
) -> DescriptorSetWithOffsets
where where
Self: Sized + 'static, Self: Sized + 'static,
I: IntoIterator<Item = u32>,
{ {
DescriptorSetWithOffsets::new(self, dynamic_offsets) DescriptorSetWithOffsets::new(self, dynamic_offsets)
} }
@ -405,10 +407,10 @@ pub struct DescriptorSetWithOffsets {
impl DescriptorSetWithOffsets { impl DescriptorSetWithOffsets {
#[inline] #[inline]
pub fn new<O>(descriptor_set: Arc<dyn DescriptorSet>, dynamic_offsets: O) -> Self pub fn new(
where descriptor_set: Arc<dyn DescriptorSet>,
O: IntoIterator<Item = u32>, dynamic_offsets: impl IntoIterator<Item = u32>,
{ ) -> Self {
let dynamic_offsets: SmallVec<_> = dynamic_offsets.into_iter().collect(); let dynamic_offsets: SmallVec<_> = dynamic_offsets.into_iter().collect();
let layout = descriptor_set.layout(); let layout = descriptor_set.layout();
let properties = layout.device().physical_device().properties(); let properties = layout.device().physical_device().properties();

View File

@ -282,10 +282,10 @@ impl UnsafeDescriptorPool {
/// - The descriptor sets must not be free'd twice. /// - The descriptor sets must not be free'd twice.
/// - The descriptor sets must not be in use by the GPU. /// - The descriptor sets must not be in use by the GPU.
/// ///
pub unsafe fn free_descriptor_sets<I>(&mut self, descriptor_sets: I) -> Result<(), OomError> pub unsafe fn free_descriptor_sets(
where &mut self,
I: IntoIterator<Item = UnsafeDescriptorSet>, descriptor_sets: impl IntoIterator<Item = UnsafeDescriptorSet>,
{ ) -> Result<(), OomError> {
let sets: SmallVec<[_; 8]> = descriptor_sets let sets: SmallVec<[_; 8]> = descriptor_sets
.into_iter() .into_iter()
.map(|s| s.internal_object()) .map(|s| s.internal_object())

View File

@ -859,10 +859,7 @@ impl ImageViewCreateInfo {
/// Returns an `ImageViewCreateInfo` with the `view_type` determined from the image type and /// 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 /// array layers, and `subresource_range` determined from the image format and covering the
/// whole image. /// whole image.
pub fn from_image<I>(image: &I) -> Self pub fn from_image(image: &(impl ImageAccess + ?Sized)) -> Self {
where
I: ImageAccess + ?Sized,
{
Self { Self {
view_type: match image.dimensions() { view_type: match image.dimensions() {
ImageDimensions::Dim1d { ImageDimensions::Dim1d {

View File

@ -84,10 +84,7 @@ impl VulkanLibrary {
} }
/// Loads a custom Vulkan library. /// Loads a custom Vulkan library.
pub fn with_loader<L>(loader: L) -> Result<Arc<Self>, LoadingError> pub fn with_loader(loader: impl Loader + 'static) -> Result<Arc<Self>, LoadingError> {
where
L: Loader + 'static,
{
let fns = EntryFunctions::load(|name| unsafe { let fns = EntryFunctions::load(|name| unsafe {
loader loader
.get_instance_proc_addr(ash::vk::Instance::null(), name.as_ptr()) .get_instance_proc_addr(ash::vk::Instance::null(), name.as_ptr())
@ -110,10 +107,7 @@ impl VulkanLibrary {
})) }))
} }
unsafe fn get_api_version<L>(loader: &L) -> Result<Version, VulkanError> unsafe fn get_api_version(loader: &impl Loader) -> Result<Version, VulkanError> {
where
L: Loader,
{
// Per the Vulkan spec: // Per the Vulkan spec:
// If the vkGetInstanceProcAddr returns NULL for vkEnumerateInstanceVersion, it is a // If the vkGetInstanceProcAddr returns NULL for vkEnumerateInstanceVersion, it is a
// Vulkan 1.0 implementation. Otherwise, the application can call vkEnumerateInstanceVersion // 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. /// - The dynamic library must be a valid Vulkan implementation.
/// ///
pub unsafe fn new<P>(path: P) -> Result<DynamicLibraryLoader, LoadingError> pub unsafe fn new(path: impl AsRef<Path>) -> Result<DynamicLibraryLoader, LoadingError> {
where
P: AsRef<Path>,
{
let vk_lib = Library::new(path.as_ref()).map_err(LoadingError::LibraryLoadFailure)?; let vk_lib = Library::new(path.as_ref()).map_err(LoadingError::LibraryLoadFailure)?;
let get_instance_proc_addr = *vk_lib let get_instance_proc_addr = *vk_lib

View File

@ -141,10 +141,10 @@ impl PipelineCache {
/// ///
// FIXME: vkMergePipelineCaches is not thread safe for the destination cache // FIXME: vkMergePipelineCaches is not thread safe for the destination cache
// TODO: write example // TODO: write example
pub fn merge<'a, I>(&self, pipelines: I) -> Result<(), OomError> pub fn merge<'a>(
where &self,
I: IntoIterator<Item = &'a &'a Arc<PipelineCache>>, pipelines: impl IntoIterator<Item = &'a &'a Arc<PipelineCache>>,
{ ) -> Result<(), OomError> {
unsafe { unsafe {
let fns = self.device.fns(); let fns = self.device.fns();

View File

@ -492,13 +492,10 @@ impl Sampler {
} }
/// Checks whether this sampler is compatible with `image_view`. /// Checks whether this sampler is compatible with `image_view`.
pub fn check_can_sample<I>( pub fn check_can_sample(
&self, &self,
image_view: &I, image_view: &(impl ImageViewAbstract + ?Sized),
) -> Result<(), SamplerImageViewIncompatibleError> ) -> Result<(), SamplerImageViewIncompatibleError> {
where
I: ImageViewAbstract + ?Sized,
{
/* /*
Note: Most of these checks come from the Instruction/Sampler/Image View Validation Note: Most of these checks come from the Instruction/Sampler/Image View Validation
section, and are not strictly VUIDs. section, and are not strictly VUIDs.