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 users to specify a custom path to the rust_embed crate in generated code #232

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Wulf
Copy link

@Wulf Wulf commented Feb 7, 2024

Hi @pyrossh, thanks for taking the time to maintain this crate and oversee the community's contributions 🙌

I'd like to request this feature: allow end users to specify a custom path to the rust_embed crate (in case rust_embed is not in-scope, for whatever reason).

Changes

  • Added a crate_path attribute which allows the end-user to specify the path to the rust_embed crate
    #[derive(custom::path::rust_embed::RustEmbed)]
    #[crate_path = "custom::path::rust_embed"] // <--
    #[folder = "examples/public/"]
    struct Asset;
  • Added a test to make sure this doesn't break in the future :)

Notes

  • I tried to use crate as the attribute name instead of crate_path (just like serde does), but proc_macro_derive did not accept 'crate' as an attribute name.

@AzureMarker
Copy link
Collaborator

I don't understand the use case. Why doesn't changing to ::rust_embed work? That's the recommended approach to the problem of when users rename a crate. See for example https://users.rust-lang.org/t/how-to-unambiguously-refer-to-a-particular-crate-from-a-proc-macro/39061. I don't think the current approach should be merged.

@Wulf
Copy link
Author

Wulf commented Feb 7, 2024

hey @AzureMarker, hope all is well. Thanks for the review :)

The use case here is to allow end-users to re-export the crate for use in another crate. This is useful in dependency management -- imagine adding rust_embed to several helper crates compared to just adding it to a single common crate that helper crates can depend on. Here's how it's currently done in serde. Let me know if I can clarify or if there's another approach you'd prefer.

@AzureMarker
Copy link
Collaborator

I see, thanks for clarifying. Personally I would use the workspace dependencies feature instead (https://doc.rust-lang.org/cargo/reference/workspaces.html#the-dependencies-table), but I understand that re-exporting has some other advantages and also works outside of a single workspace.

The changes look fine, but I'll also ask @pyrossh to approve since it's a new feature.

@pyrossh
Copy link
Owner

pyrossh commented Feb 9, 2024

@Wulf It is possible for you to try out using workspaces assuming you don't need to do much refactor? For example this is how zed have done it.

But anyways the change is pretty small and doesn't seem to break anything so can merge it. Let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants