-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Labels
Description
Currently we use the proc_macro_crate to find the Sylvia crate. This way the generated code can work even if an alias was used for the dependency.
pub(crate) fn crate_module() -> Path {
use proc_macro_crate::{crate_name, FoundCrate};
match crate_name("sylvia").expect("sylvia is not found in Cargo.toml") {
FoundCrate::Itself => parse_quote!(sylvia),
FoundCrate::Name(name) => {
let ident = syn::Ident::new(&name, proc_macro2::Span::mixed_site());
parse_quote!(#ident)
}
}
}
If however in the future a need for providing custom path to the Sylvia crate would occur we could consider adding serde-like functionality:
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
#[serde(crate = "sylvia::serde")]
pub struct AllAllowancesResponse {
pub allowances: Vec<AllowanceInfo>,
}
This was also discussed here https://users.rust-lang.org/t/how-to-express-crate-path-in-procedural-macros/91274/17.