debug name from bevy

This commit is contained in:
janis 2026-04-03 00:17:33 +02:00
parent 82d37247d8
commit 297b79d347

View file

@ -1,4 +1,7 @@
use std::ops::{Deref, DerefMut}; use std::{
borrow::Cow,
ops::{Deref, DerefMut},
};
use ash::vk; use ash::vk;
use bytemuck::{Pod, Zeroable}; 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<Cow<'static, str>> 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<String> for DebugName {
fn from(_value: String) -> Self {
Self {
#[cfg(debug_assertions)]
name: Cow::Owned(_value),
}
}
}
#[macro_export] #[macro_export]
macro_rules! def_monotonic_id { macro_rules! def_monotonic_id {