use alloc::string::String;
pub(crate) fn normalized<T: ?Sized>() -> String {
normalize(core::any::type_name::<T>())
}
pub(crate) fn normalize(name: &str) -> String {
name.replace("<'_, ", "<").replace("<'_>", "")
}
#[cfg(test)]
#[coverage(off)]
mod tests {
use super::*;
#[test]
fn test_normalize_strips_leading_anonymous_lifetime() {
assert_eq!(normalize("SomeType<'_, u32>"), "SomeType<u32>");
}
#[test]
fn test_normalize_strips_sole_anonymous_lifetime() {
assert_eq!(normalize("SomeType<'_>"), "SomeType");
}
#[test]
fn test_normalize_is_noop_when_no_anonymous_lifetime_present() {
assert_eq!(normalize("SomeType<u32>"), "SomeType<u32>");
assert_eq!(normalize("path::to::AType"), "path::to::AType");
}
#[test]
fn test_normalize_handles_nested_anonymous_lifetimes() {
assert_eq!(normalize("Outer<Inner<'_, u8>, '_>"), "Outer<Inner<u8>, '_>");
assert_eq!(normalize("Wrap<SomeType<'_>>"), "Wrap<SomeType>");
}
}