use bevy_asset::{Asset, Handle};
use std::fmt;
#[doc(hidden)]
pub struct HandleDisplay<'a, T: Asset>(&'a Handle<T>);
impl<'a, A: Asset> fmt::Display for HandleDisplay<'a, A> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(path) = self.0.path() {
write!(f, "path {path}")
} else {
write!(f, "id {}", self.0.id())
}
}
}
impl<'a, A: Asset> fmt::Debug for HandleDisplay<'a, A> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(path) = self.0.path() {
write!(f, "path {path:?}")
} else {
write!(f, "id {:?}", self.0.id())
}
}
}
pub trait DisplayProxy {
type D<'a>: fmt::Display + fmt::Debug
where
Self: 'a;
fn display<'a>(&'a self) -> Self::D<'a>;
}
impl<A: Asset> DisplayProxy for Handle<A> {
type D<'a> = HandleDisplay<'a, A>;
fn display<'a>(&'a self) -> Self::D<'a> {
HandleDisplay(self)
}
}