blob: fc301ab3e43706ecd3bd0cccba1d8fb91ca3d3a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
use quote::ToTokens;
use syn::punctuated::Pair;
pub trait SynPathExt
{
/// Converts the [`syn::Path`] to a [`String`].
fn to_string(&self) -> String;
}
impl SynPathExt for syn::Path
{
fn to_string(&self) -> String
{
self.segments
.pairs()
.map(Pair::into_tuple)
.map(|(segment, opt_punct)| {
let segment_ident = &segment.ident;
format!(
"{}{}",
segment_ident,
opt_punct.map_or_else(String::new, |punct| punct
.to_token_stream()
.to_string())
)
})
.collect()
}
}
|