[PATCH] Make Way to avoid compile failure on undefined env

26 views
Skip to first unread message

Tommy Yu

unread,
May 20, 2026, 12:48:36 AMMay 20
to rust-embed-devs
Hi,

I've created a patch that extends `allow_empty` to prevent undefined environment variable from causing a compilation error.


The intention of this patch is to allow a library that might offer a hook to optionally embed files to compile successfully even if the environment variable isn't set, which may be the case during `cargo clippy` or other integration tests.

Regards,
Tommy.

Peter John

unread,
May 23, 2026, 11:40:25 AMMay 23
to rust-embed-devs
Hi Tommy,

Thanks. I've applied your patch and will release a new version soon with the changes.

Regards,
Peter

Tommy Yu

unread,
May 24, 2026, 1:34:03 AMMay 24
to rust-embed-devs
Hi Peter,

Apologies for this correction after your merge, but if you haven't got around to making the release I spotted a couple lines that needed removing/adjusting in my patch, as there was a redundant `Option` and a commented line that should be removed in the final version as those were part of the exploration of the code base.  Patch at <https://codeberg.org/metatoaster/rust-embed/commit/af505edf473c3765be791db2e9aff04011769236.patch>, or as follows:

```
 impl/src/lib.rs | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/impl/src/lib.rs b/impl/src/lib.rs
index e541db5..d106425 100644
--- a/impl/src/lib.rs
+++ b/impl/src/lib.rs
@@ -368,7 +368,7 @@ fn impl_rust_embed(ast: &syn::DeriveInput) -> syn::Result<TokenStream2> {
       "#[derive(RustEmbed)] must contain one attribute like this #[folder = \"examples/public/\"]",
     ));
   }
-  let folder_path = Some(folder_paths.remove(0));
+  let folder_path = folder_paths.remove(0);
 
   let prefix = find_attribute_values(ast, "prefix").into_iter().next();
   let includes = find_attribute_values(ast, "include");
@@ -384,9 +384,8 @@ fn impl_rust_embed(ast: &syn::DeriveInput) -> syn::Result<TokenStream2> {
     ));
   }
 
-    // .map_err(|v| syn::Error::new_spanned(ast, v.to_string()))?
   #[cfg(feature = "interpolate-folder-path")]
-  let folder_path = match shellexpand::full(&folder_path.unwrap()) {
+  let folder_path = match shellexpand::full(&folder_path) {
     Ok(v) => Ok(Some(v.to_string())),
     Err(v) if v.cause == std::env::VarError::NotPresent && allow_missing => Ok(None),
     Err(v) => Err(syn::Error::new_spanned(ast, v.to_string())),
```

Regards,
Tommy.

Peter John

unread,
May 24, 2026, 5:18:20 AMMay 24
to rust-embed-devs
Hi Tommy,

No worries. I did see the comment, but didn't mind it. Some of the tests were failing I've made a fix for it.

From 977cfc03c219094cec643e5768ba73d4f9ade739 Mon Sep 17 00:00:00 2001
From: pyrossh <pyrossh>
Date: Sun, 24 May 2026 14:47:34 +0530
Subject: [PATCH] Fix folder_path not being an Option

---
impl/src/lib.rs | 2 ++
1 file changed, 2 insertions(+)

diff --git a/impl/src/lib.rs b/impl/src/lib.rs
index 731e671..927e3ea 100644
--- a/impl/src/lib.rs
+++ b/impl/src/lib.rs
@@ -390,6 +390,8 @@ fn impl_rust_embed(ast: &syn::DeriveInput) -> syn::Result<TokenStream2> {
Err(v) if v.cause == std::env::VarError::NotPresent && allow_missing => Ok(None),
Err(v) => Err(syn::Error::new_spanned(ast, v.to_string())),
}?;
+ #[cfg(not(feature = "interpolate-folder-path"))]
+ let folder_path = Some(folder_path);
// Base relative paths on the Cargo.toml location
let (relative_path, absolute_folder_path) = if let Some(folder_path) = folder_path {
--
2.54.0


Reply all
Reply to author
Forward
0 new messages