From 9526e772e22411dea91602f1ca8895e36fbc4082 Mon Sep 17 00:00:00 2001 From: marc0246 <40955683+marc0246@users.noreply.github.com> Date: Tue, 24 Oct 2023 19:14:51 +0200 Subject: [PATCH] Error naming consistency (#2370) --- vulkano/src/buffer/allocator.rs | 4 ++-- vulkano/src/buffer/mod.rs | 28 ++++++++++++++-------------- vulkano/src/image/mod.rs | 18 +++++++++--------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/vulkano/src/buffer/allocator.rs b/vulkano/src/buffer/allocator.rs index 6f8b4f65..3e356cfa 100644 --- a/vulkano/src/buffer/allocator.rs +++ b/vulkano/src/buffer/allocator.rs @@ -10,7 +10,7 @@ //! Efficiently suballocates buffers into smaller subbuffers. use super::{ - sys::BufferCreateInfo, Buffer, BufferAllocateError, BufferContents, BufferMemory, BufferUsage, + sys::BufferCreateInfo, AllocateBufferError, Buffer, BufferContents, BufferMemory, BufferUsage, Subbuffer, }; use crate::{ @@ -370,7 +370,7 @@ where DeviceLayout::from_size_alignment(self.arena_size, 1).unwrap(), ) .map_err(|err| match err { - Validated::Error(BufferAllocateError::AllocateMemory(err)) => err, + Validated::Error(AllocateBufferError::AllocateMemory(err)) => err, // We don't use sparse-binding, concurrent sharing or external memory, therefore the // other errors can't happen. _ => unreachable!("{err:?}"), diff --git a/vulkano/src/buffer/mod.rs b/vulkano/src/buffer/mod.rs index 0f8e0f04..cb3d14e7 100644 --- a/vulkano/src/buffer/mod.rs +++ b/vulkano/src/buffer/mod.rs @@ -244,7 +244,7 @@ impl Buffer { create_info: BufferCreateInfo, allocation_info: AllocationCreateInfo, data: T, - ) -> Result, Validated> + ) -> Result, Validated> where T: BufferContents, { @@ -275,7 +275,7 @@ impl Buffer { create_info: BufferCreateInfo, allocation_info: AllocationCreateInfo, iter: I, - ) -> Result, Validated> + ) -> Result, Validated> where T: BufferContents, I: IntoIterator, @@ -310,7 +310,7 @@ impl Buffer { allocator: Arc, create_info: BufferCreateInfo, allocation_info: AllocationCreateInfo, - ) -> Result, Validated> + ) -> Result, Validated> where T: BufferContents, { @@ -337,7 +337,7 @@ impl Buffer { create_info: BufferCreateInfo, allocation_info: AllocationCreateInfo, len: DeviceSize, - ) -> Result, Validated> + ) -> Result, Validated> where T: BufferContents, { @@ -356,7 +356,7 @@ impl Buffer { create_info: BufferCreateInfo, allocation_info: AllocationCreateInfo, len: DeviceSize, - ) -> Result, Validated> + ) -> Result, Validated> where T: BufferContents + ?Sized, { @@ -383,7 +383,7 @@ impl Buffer { mut create_info: BufferCreateInfo, allocation_info: AllocationCreateInfo, layout: DeviceLayout, - ) -> Result, Validated> { + ) -> Result, Validated> { assert!(layout.alignment().as_devicesize() <= 64); // TODO: Enable once sparse binding materializes // assert!(!allocate_info.flags.contains(BufferCreateFlags::SPARSE_BINDING)); @@ -398,7 +398,7 @@ impl Buffer { let raw_buffer = RawBuffer::new(allocator.device().clone(), create_info).map_err(|err| match err { - Validated::Error(err) => Validated::Error(BufferAllocateError::CreateBuffer(err)), + Validated::Error(err) => Validated::Error(AllocateBufferError::CreateBuffer(err)), Validated::ValidationError(err) => err.into(), })?; let mut requirements = *raw_buffer.memory_requirements(); @@ -411,11 +411,11 @@ impl Buffer { allocation_info, Some(DedicatedAllocation::Buffer(&raw_buffer)), ) - .map_err(BufferAllocateError::AllocateMemory)?; + .map_err(AllocateBufferError::AllocateMemory)?; let allocation = unsafe { ResourceMemory::from_allocation(allocator, allocation) }; let buffer = raw_buffer.bind_memory(allocation).map_err(|(err, _, _)| { - err.map(BufferAllocateError::BindMemory) + err.map(AllocateBufferError::BindMemory) .map_validation(|err| err.add_context("RawBuffer::bind_memory")) })?; @@ -569,13 +569,13 @@ impl Hash for Buffer { /// Error that can happen when allocating a new buffer. #[derive(Clone, Debug)] -pub enum BufferAllocateError { +pub enum AllocateBufferError { CreateBuffer(VulkanError), AllocateMemory(MemoryAllocatorError), BindMemory(VulkanError), } -impl Error for BufferAllocateError { +impl Error for AllocateBufferError { fn source(&self) -> Option<&(dyn Error + 'static)> { match self { Self::CreateBuffer(err) => Some(err), @@ -585,7 +585,7 @@ impl Error for BufferAllocateError { } } -impl Display for BufferAllocateError { +impl Display for AllocateBufferError { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { Self::CreateBuffer(_) => write!(f, "creating the buffer failed"), @@ -595,8 +595,8 @@ impl Display for BufferAllocateError { } } -impl From for Validated { - fn from(err: BufferAllocateError) -> Self { +impl From for Validated { + fn from(err: AllocateBufferError) -> Self { Self::Error(err) } } diff --git a/vulkano/src/image/mod.rs b/vulkano/src/image/mod.rs index c0aa45d5..1acc0fa3 100644 --- a/vulkano/src/image/mod.rs +++ b/vulkano/src/image/mod.rs @@ -148,14 +148,14 @@ impl Image { allocator: Arc, create_info: ImageCreateInfo, allocation_info: AllocationCreateInfo, - ) -> Result, Validated> { + ) -> Result, Validated> { // TODO: adjust the code below to make this safe assert!(!create_info.flags.intersects(ImageCreateFlags::DISJOINT)); let allocation_type = create_info.tiling.into(); let raw_image = RawImage::new(allocator.device().clone(), create_info).map_err(|err| match err { - Validated::Error(err) => Validated::Error(ImageAllocateError::CreateImage(err)), + Validated::Error(err) => Validated::Error(AllocateImageError::CreateImage(err)), Validated::ValidationError(err) => err.into(), })?; let requirements = raw_image.memory_requirements()[0]; @@ -167,11 +167,11 @@ impl Image { allocation_info, Some(DedicatedAllocation::Image(&raw_image)), ) - .map_err(ImageAllocateError::AllocateMemory)?; + .map_err(AllocateImageError::AllocateMemory)?; let allocation = unsafe { ResourceMemory::from_allocation(allocator, allocation) }; let image = raw_image.bind_memory([allocation]).map_err(|(err, _, _)| { - err.map(ImageAllocateError::BindMemory) + err.map(AllocateImageError::BindMemory) .map_validation(|err| err.add_context("RawImage::bind_memory")) })?; @@ -572,13 +572,13 @@ impl Hash for Image { /// Error that can happen when allocating a new image. #[derive(Clone, Debug)] -pub enum ImageAllocateError { +pub enum AllocateImageError { CreateImage(VulkanError), AllocateMemory(MemoryAllocatorError), BindMemory(VulkanError), } -impl Error for ImageAllocateError { +impl Error for AllocateImageError { fn source(&self) -> Option<&(dyn Error + 'static)> { match self { Self::CreateImage(err) => Some(err), @@ -588,7 +588,7 @@ impl Error for ImageAllocateError { } } -impl Display for ImageAllocateError { +impl Display for AllocateImageError { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { Self::CreateImage(_) => write!(f, "creating the image failed"), @@ -598,8 +598,8 @@ impl Display for ImageAllocateError { } } -impl From for Validated { - fn from(err: ImageAllocateError) -> Self { +impl From for Validated { + fn from(err: AllocateImageError) -> Self { Self::Error(err) } }