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

Having a fallback when an ENV variable does not exist for interpolate-folder-path #176

Closed
rbozan opened this issue Apr 30, 2022 · 4 comments
Labels

Comments

@rbozan
Copy link

rbozan commented Apr 30, 2022

Hi, thanks for the crate,

Basically I have the interpolate-folder-path functionality enabled and use this piece of code for loading in the assets:

#[derive(RustEmbed)]
#[folder = "$CURRENT_SCENARIO_DIR/output"]
pub struct Content;

However I would like to have an "empty" Content in this case when the ENV variable does not exist. You can of course circumvent this by somehow setting the ENV variable CURRENT_SCENARIO_DIR to some invalid path before starting the compilation, but is there not an easier way to fallback to something else?

The current behavior when the ENV variable does not exist is just failing to compile completely:

help: message: called `Result::unwrap()` on an `Err` value: LookupError { var_name: "CURRENT_SCENARIO_DIR", cause: NotPresent }

Another option (which would work for my use case) would be something like falling back to another ENV variable, so you could maybe do:

#[folder = "($CURRENT_SCENARIO_DIR || $PWD)/output"]

Thanks

@rbozan rbozan changed the title Having a fallback when an ENV variable does not exist for interpolate-folder-path Having a fallback when an ENV variable does not exist for interpolate-folder-path Apr 30, 2022
@AzureMarker
Copy link
Collaborator

AzureMarker commented Apr 30, 2022

Have you tried setting the env variable in your build.rs script? I think the current behavior is good because it's explicit.

@AzureMarker
Copy link
Collaborator

Additionally, I would try to avoid having any logic in the folder string. That kind of thing should be in your build.rs script.

@rbozan
Copy link
Author

rbozan commented May 1, 2022

Well I guess for my use case I can also use [env] in my Cargo config as that would fix it. But still it would be nice if an folder does not exist it wouldn't panic but you can silently ignore it so the Content in this case would just be empty as well. The issue can be closed though if you don't agree

@AzureMarker
Copy link
Collaborator

I recommend using the built-in functionality of https://doc.rust-lang.org/cargo/reference/build-scripts.html (or [env] as you suggested), especially if you need logic around the folder path.

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