int-enum-impl 0.5.0

Implementation detail of the `int-enum` crate.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
use proc_macro_crate::FoundCrate;
use quote::format_ident;
use syn::{parse_quote, Path};

pub fn with_crate_path<F: Fn(&Path) -> R, R>(f: F) -> R {
    let int_enum = match proc_macro_crate::crate_name("int-enum") {
        Ok(FoundCrate::Name(name)) => format_ident!("{}", name),
        Ok(FoundCrate::Itself) | Err(_) => format_ident!("int_enum"),
    };
    let path = parse_quote!(::#int_enum);
    f(&path)
}