From e2c43489595de4855a8af531f994f79c42299745 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:48:28 +0200 Subject: [PATCH] replace `.then_some(()).ok_or_else(e)` with `if`s --- wgpu-core/src/device/resource.rs | 8 +++-- wgpu-core/src/resource.rs | 50 +++++++++++++++++--------------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index e6eb06199..de2e72ea1 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -312,9 +312,11 @@ impl Device { } pub fn check_is_valid(&self) -> Result<(), DeviceError> { - self.is_valid() - .then_some(()) - .ok_or_else(|| DeviceError::Invalid(self.error_ident())) + if self.is_valid() { + Ok(()) + } else { + Err(DeviceError::Invalid(self.error_ident())) + } } pub(crate) fn release_queue(&self, queue: A::Queue) { diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 9949ec47e..42dcd77e7 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -158,28 +158,29 @@ pub(crate) trait ParentDevice: Resource { fn device(&self) -> &Arc>; fn same_device_as>(&self, other: &O) -> Result<(), DeviceError> { - self.device() - .is_equal(other.device()) - .then_some(()) - .ok_or_else(|| { - DeviceError::DeviceMismatch(Box::new(DeviceMismatch { - res: self.error_ident(), - res_device: self.device().error_ident(), - target: Some(other.error_ident()), - target_device: other.device().error_ident(), - })) - }) + if self.device().is_equal(other.device()) { + Ok(()) + } else { + Err(DeviceError::DeviceMismatch(Box::new(DeviceMismatch { + res: self.error_ident(), + res_device: self.device().error_ident(), + target: Some(other.error_ident()), + target_device: other.device().error_ident(), + }))) + } } fn same_device(&self, device: &Arc>) -> Result<(), DeviceError> { - self.device().is_equal(device).then_some(()).ok_or_else(|| { - DeviceError::DeviceMismatch(Box::new(DeviceMismatch { + if self.device().is_equal(device) { + Ok(()) + } else { + Err(DeviceError::DeviceMismatch(Box::new(DeviceMismatch { res: self.error_ident(), res_device: self.device().error_ident(), target: None, target_device: device.error_ident(), - })) - }) + }))) + } } } @@ -515,14 +516,15 @@ impl Buffer { self: &Arc, expected: wgt::BufferUsages, ) -> Result<(), MissingBufferUsageError> { - self.usage - .contains(expected) - .then_some(()) - .ok_or_else(|| MissingBufferUsageError { + if self.usage.contains(expected) { + Ok(()) + } else { + Err(MissingBufferUsageError { res: self.error_ident(), actual: self.usage, expected, }) + } } /// Returns the mapping callback in case of error so that the callback can be fired outside @@ -996,15 +998,15 @@ impl Texture { &self, expected: wgt::TextureUsages, ) -> Result<(), MissingTextureUsageError> { - self.desc - .usage - .contains(expected) - .then_some(()) - .ok_or_else(|| MissingTextureUsageError { + if self.desc.usage.contains(expected) { + Ok(()) + } else { + Err(MissingTextureUsageError { res: self.error_ident(), actual: self.desc.usage, expected, }) + } } }