aboutsummaryrefslogtreecommitdiff
path: root/macros/src/util/syn_path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'macros/src/util/syn_path.rs')
-rw-r--r--macros/src/util/syn_path.rs39
1 files changed, 24 insertions, 15 deletions
diff --git a/macros/src/util/syn_path.rs b/macros/src/util/syn_path.rs
index 0e1b8f4..fc301ab 100644
--- a/macros/src/util/syn_path.rs
+++ b/macros/src/util/syn_path.rs
@@ -1,21 +1,30 @@
use quote::ToTokens;
use syn::punctuated::Pair;
-pub fn syn_path_to_string(path: &syn::Path) -> String
+pub trait SynPathExt
{
- path.segments
- .pairs()
- .map(Pair::into_tuple)
- .map(|(segment, opt_punct)| {
- let segment_ident = &segment.ident;
+ /// 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()
+ format!(
+ "{}{}",
+ segment_ident,
+ opt_punct.map_or_else(String::new, |punct| punct
+ .to_token_stream()
+ .to_string())
+ )
+ })
+ .collect()
+ }
}