diff --git a/crates/renderer/src/util.rs b/crates/renderer/src/util.rs index 761a3c7..9c34d0b 100644 --- a/crates/renderer/src/util.rs +++ b/crates/renderer/src/util.rs @@ -1,4 +1,7 @@ -use std::ops::{Deref, DerefMut}; +use std::{ + borrow::Cow, + ops::{Deref, DerefMut}, +}; use ash::vk; use bytemuck::{Pod, Zeroable}; @@ -72,7 +75,61 @@ pub(crate) mod weak_vec { } } -pub(crate) mod cow_arc {} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct DebugName { + #[cfg(debug_assertions)] + name: Cow<'static, str>, +} + +impl core::fmt::Display for DebugName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", &**self) + } +} + +impl core::fmt::Debug for DebugName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", &**self) + } +} + +impl core::ops::Deref for DebugName { + type Target = str; + + fn deref(&self) -> &Self::Target { + #[cfg(debug_assertions)] + return &self.name; + #[cfg(not(debug_assertions))] + return "FEATURE_DISABLED"; + } +} + +impl From> for DebugName { + fn from(_value: Cow<'static, str>) -> Self { + Self { + #[cfg(debug_assertions)] + name: _value, + } + } +} + +impl From<&'static str> for DebugName { + fn from(_value: &'static str) -> Self { + Self { + #[cfg(debug_assertions)] + name: Cow::Borrowed(_value), + } + } +} + +impl From for DebugName { + fn from(_value: String) -> Self { + Self { + #[cfg(debug_assertions)] + name: Cow::Owned(_value), + } + } +} #[macro_export] macro_rules! def_monotonic_id {