aboutsummaryrefslogtreecommitdiff
path: root/macros/src/util/syn_path.rs
blob: 0e1b8f47b3149a7c7fca030fee20a2d247665511 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use quote::ToTokens;
use syn::punctuated::Pair;

pub fn syn_path_to_string(path: &syn::Path) -> String
{
    path.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()
}