Comments (7)
Yeah the interpolate-folder-path
feature totally solved this for me. Maybe I should have completely read the docs before submitting and issue here!
from rust-embed.
Yeah, I definitely see that now, I've written some proc macros myself and had not taken into account how they actually work. In particular, I imagine that a const
value could be used in the debug case where the directory is searched at runtime since presumably the macro produces code in the host program that does this and thus would have access to a const
identifier. However, in the release case I see that this would not be possible since the directory is read at compile time instead.
I did a quick test and verified that you are correct in that neither include_bytes
nor include_str
work with const
identifiers, and explicitly say that they require a string literal.
I tried another approach described in a reddit post I just made here, but it also didn’t work. I’ll also note that the env
macro approach does work for include_bytes
and include_str
. If you’re as stumped as I am, we’ll see if anyone in my reddit post has any ideas for workarounds.
from rust-embed.
The value needs to be used during the proc macro execution, which doesn't have access to the rest of your program. Proc macros receive the input as tokens, so we can't resolve the value of a variable, even if it's const.
Unfortunately this means this feature is impossible.
from rust-embed.
Thinking a little more on this, it might work if include_bytes
supports it, but I don't think it does.
from rust-embed.
You can actually include whatever you want in attributes, it's just that right now the library expects a string. Whatever you write there will still just be unevaluated tokens to the macro though. The proc macro does read some metadata about the file (ex. hash, last modified time), so it does want the real path during its execution, but besides that it would technically be possible to accept an expression that resolves at compile time (ex. env macro) to a string that include_bytes would accept.
from rust-embed.
Yeah, based on my experience, I assumed that the proc macro itself is specifically looking for a string literal. I'm guessing that the syntax tree for the attribute could just be the macro expression, which does exist in syn
for example. However, unless there's a a way inside the proc macro to actually evaluate the env
macro I don't think it's possible to do this. It sounds like maybe this is just not possible.
Although, given that include_bytes
does the same kind of things at compile time, it must be possible unless it's using some special black magic. I might look into how this is accomplished.
EDIT: Ok I quickly looked into this and include_bytes
is a macro_rules!
macro that basically does nothing with a comment that this is "compiler built-in", so evidently it is actually a compiler feature. This is exactly what I meant when I referred to special black magic.
from rust-embed.
If you use the interpolate-folder-path
feature you can use environment variables in the folder string, but that doesn't help much since now you'd need to set an env variable in addition to the const.
from rust-embed.
Related Issues (20)
- Avoid panicking if the folder is missing HOT 3
- What were the breaking changes between 5.9 and 6.4 HOT 2
- Compression feature breaks incremental builds HOT 10
- Single page application (SPA) example HOT 3
- [bug] debian test failure HOT 5
- Publish utils version HOT 2
- `include` and `exclude` should at least warn if their feature isn't enabled
- Store the result from `mime_guess` statically at compile time? HOT 3
- Allow dynamically reading either from the file system or the embedded binary, with configurable runtime order HOT 1
- Getting error: pattern does not mention field `is_dir` HOT 7
- 6.5.0 release included breaking changes HOT 6
- [IGNORE] Expose an iterator over embedded filenames?
- cargo test fails HOT 2
- Clippy warning for same_name_method on generated file HOT 2
- Fails cross-compiled and run under Wine in debug mode. HOT 2
- Depending on wrong version of `walkdir`. HOT 1
- Bump `syn` ^2 HOT 1
- The `mime-guess` feature doesn't work HOT 4
- using with askama compile time templates HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-embed.