diff options
author | HampusM <hampus@hampusmat.com> | 2023-01-13 21:14:03 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-01-13 21:14:03 +0100 |
commit | 45533a946c296a3a748a645fb80869f93ad7f09a (patch) | |
tree | 529bf5f41579d80b8cc50613b90250b652acf0d9 /macros/src/util | |
parent | 133069545b0f2a1fd28b44750934cab13be5a953 (diff) |
refactor: put syn_path_to_string in a extension trait
Diffstat (limited to 'macros/src/util')
-rw-r--r-- | macros/src/util/syn_path.rs | 39 |
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() + } } |