int_enum_impl/
util.rs

1use proc_macro_crate::FoundCrate;
2use quote::format_ident;
3use syn::{parse_quote, Path};
4
5pub fn with_crate_path<F: Fn(&Path) -> R, R>(f: F) -> R {
6    let int_enum = match proc_macro_crate::crate_name("int-enum") {
7        Ok(FoundCrate::Name(name)) => format_ident!("{}", name),
8        Ok(FoundCrate::Itself) | Err(_) => format_ident!("int_enum"),
9    };
10    let path = parse_quote!(::#int_enum);
11    f(&path)
12}