aboutsummaryrefslogtreecommitdiff
path: root/macros/src/util/syn_path.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-10-01 21:15:00 +0200
committerHampusM <hampus@hampusmat.com>2023-10-01 21:15:00 +0200
commitaf88321fc14a95b3613ec11a7f665db3c468c944 (patch)
tree723853d3788e559afa65c603a12b271e6872dd32 /macros/src/util/syn_path.rs
parent1fc0371867b02127a5da63f01f03d264b382b552 (diff)
refactor: remove impossible unwrap in injectable macro
This unwrap couldn't possibly be Err and can be removed by creating method call expressions by hand
Diffstat (limited to 'macros/src/util/syn_path.rs')
-rw-r--r--macros/src/util/syn_path.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/macros/src/util/syn_path.rs b/macros/src/util/syn_path.rs
index 88182cc..26e2597 100644
--- a/macros/src/util/syn_path.rs
+++ b/macros/src/util/syn_path.rs
@@ -32,3 +32,29 @@ impl SynPathExt for syn::Path
)
}
}
+
+macro_rules! syn_path {
+ ($first_segment: ident $(::$segment: ident)*) => {
+ ::syn::Path {
+ leading_colon: None,
+ segments: ::syn::punctuated::Punctuated::from_iter([
+ $crate::util::syn_path::syn_path_segment!($first_segment),
+ $($crate::util::syn_path::syn_path_segment!($segment),)*
+ ])
+ }
+ };
+}
+
+macro_rules! syn_path_segment {
+ ($segment: ident) => {
+ ::syn::PathSegment {
+ ident: ::proc_macro2::Ident::new(
+ stringify!($segment),
+ ::proc_macro2::Span::call_site(),
+ ),
+ arguments: ::syn::PathArguments::None,
+ }
+ };
+}
+
+pub(crate) use {syn_path, syn_path_segment};