use std::borrow::Cow;
pub fn path_to_string(path: &syn::Path) -> String {
path.segments
.iter()
.enumerate()
.flat_map(|(i, s)| {
if i == 0 {
[Cow::Borrowed(""), s.ident.to_string().into()]
} else {
[Cow::Borrowed("::"), s.ident.to_string().into()]
}
})
.collect()
}
#[cfg(test)]
mod tests {
use syn::parse_quote;
use super::path_to_string;
#[test]
fn simple_ident() {
assert_eq!(path_to_string(&parse_quote!(a)), "a");
}
#[test]
fn simple_path() {
assert_eq!(path_to_string(&parse_quote!(a::b)), "a::b");
}
}