crate_paths/lib.rs
1use derive_more::Display;
2
3/// A `syn::Path` like definition.
4///
5/// This is a workaround for `syn::Path` since it isn't const.
6#[derive(Debug, Display)]
7pub struct Path<'a>(&'a str);
8
9impl<'a> Path<'a> {
10 pub const fn new(path: &'a str) -> Self {
11 Path(path)
12 }
13}
14
15impl quote::ToTokens for Path<'_> {
16 fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
17 let parsed: syn::Path = syn::parse_str(self.0).unwrap();
18 parsed.to_tokens(tokens);
19 }
20}
21
22#[cfg(feature = "macros")]
23pub use crate_paths_macros::*;