use proc_macro_crate::{
Error,
FoundCrate,
};
use proc_macro2::Span;
use quote::format_ident;
use syn::{
DeriveInput,
Path,
parse_quote,
};
pub(crate) fn resolve(
input: &DeriveInput,
result: Result<FoundCrate, Error>,
itself: Path,
error_context: &str,
) -> syn::Result<Path> {
match result {
Ok(FoundCrate::Itself) => Ok(itself),
Ok(FoundCrate::Name(name)) => {
let identifier = format_ident!(
"{}",
name.replace('-', "_"),
span = Span::call_site()
);
Ok(parse_quote!(::#identifier))
}
Err(error) => Err(syn::Error::new_spanned(
input,
format!("{error_context}: {error}"),
)),
}
}