Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user defined path to Sylvia crate #423

Open
jawoznia opened this issue Aug 26, 2024 · 2 comments
Open

Allow user defined path to Sylvia crate #423

jawoznia opened this issue Aug 26, 2024 · 2 comments
Labels

Comments

@jawoznia
Copy link
Collaborator

jawoznia commented Aug 26, 2024

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.

@jawoznia jawoznia added the idea label Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants
@jawoznia and others