pub struct PathUtils;
impl PathUtils {
#[inline]
#[must_use]
pub fn short_name(path: &str) -> &str {
path.rsplit("::").next().unwrap_or(path)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn short_name_qualified_path() {
assert_eq!(PathUtils::short_name("std::vec::Vec"), "Vec");
assert_eq!(
PathUtils::short_name("std::collections::HashMap"),
"HashMap"
);
assert_eq!(PathUtils::short_name("tokio::sync::mpsc::Sender"), "Sender");
}
#[test]
fn short_name_simple() {
assert_eq!(PathUtils::short_name("Vec"), "Vec");
assert_eq!(PathUtils::short_name("Clone"), "Clone");
assert_eq!(PathUtils::short_name("u32"), "u32");
}
#[test]
fn short_name_edge_cases() {
assert_eq!(PathUtils::short_name(""), "");
assert_eq!(PathUtils::short_name("::"), "");
assert_eq!(PathUtils::short_name("foo::"), "");
assert_eq!(PathUtils::short_name("::foo"), "foo");
}
#[test]
fn short_name_with_turbofish() {
assert_eq!(PathUtils::short_name("Type::<T>"), "<T>");
assert_eq!(PathUtils::short_name("Type:T"), "Type:T");
}
}