Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an issue that I stumbled upon when working on #21, which made me create and auto-implement new traits (
URIDCacheMapping
), I noticed that they currently rely on the appropriate traits/types to be imported into the current scope, hence "leaking" a bit everywhere to the end-user, who has to import items they don't use.This is because the proc-macro currently generates things along the lines of:
…which fails if
FeatureCollection
is not into scope.The usual solution would be to do something along the lines of:
However, the LV2 Core crate can be imported through either
lv2
orlv2_core
directly, and we can't easily know which one in advance.Other proc-macro-heavy crates like
serde
tackles the multiple-name problem by assuming you simply useserde
by default, and exposes an extra attribute to allow the user to change the imported path like this:This works for them because people renaming the crate/importing it through another is a very rare occurence.
However in our case, we recommend using
lv2
for prototyping (or if you really need the whole shebang), and using thelv2-xxx
crates for more optimized builds. Therefore the expected number of users for each is around 50/50 ant there really isn't a sensible default.My solution here is to use the
proc-macro-crate
crate, that checks inCargo.toml
which crate is used and uses the right one (or fallbacks tolv2_core
), while also supporting renaming.I'm not too keen on introducing an additional dependency (although it's only a build-time dependency), but it's the only robust solution I have found to work that allows to make the proc-macros hygienic. (I have tried introducing additional
extern crate
oruse
statement, but it always break some test or another). 😕