Comments (6)
For example :
in directory
/embed
/embed/some_dir
/embed/some_dir/myfile.data
#[derive(RustEmbed)]
#[folder = "embed/"]
struct Asset;
fn is_dir(path:&str) -> bool {
Asset::is_dir("embed/some_dir")
}
from rust-embed.
We don't have that API, but it would be a good addition to https://docs.rs/rust-embed/6.3.0/rust_embed/struct.Metadata.html
from rust-embed.
Fixed in #193
from rust-embed.
@markijohn Could you please elaborate on your usecase, in what setting would you need to know why an entry is a directory?
The embedded files are known at compile time otherwise they are not included in the binary.
from rust-embed.
Reopening since the PR got reverted. @markijohn can you elaborate on your use case? What are you trying to achieve with an is_dir
function?
from rust-embed.
I am sorry for the late comment. This was arbitrarily modified a long time ago to the following, but I wanted to know if it could be done without 'iter()' for optimization when there are a lot of embedded files and directories.
embed/somedir/file.txt
embed/somefile
#[macro_use]
extern crate rust_embed;
#[derive(RustEmbed)]
#[folder = "embed/"]
struct Asset;
fn is_exist_dir(path:&str) -> bool {
// Asset::is_dir( path ) ?
if path.ends_with("/") {
Asset::iter().find( |v| v.starts_with(path) ).is_some()
} else {
// let added_pathsep = format!("{}/", path);
// Asset::iter().find( |v| v.starts_with( &added_pathsep ) ).is_some()
Asset::iter().find( |v| v.starts_with( path ) && v[path.len() ..].starts_with('/') ).is_some()
}
}
fn main() {
let user_input = "somedir";
assert!( is_exist_dir(user_input) );
let user_input = "somefile";
assert!( !is_exist_dir(user_input) );
}
from rust-embed.
Related Issues (20)
- 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
- Fix compression with interpolated env HOT 2
- Clarify MSRV policy HOT 7
- error[E0609]: no field `data` on type `Cow<'_, [u8]>` HOT 1
- Is there a way to include files based on an externally generated list HOT 6
- Rename RustEmbed trait to Embed? HOT 5
- Axum 0.7.1 - no function or associated item named `get` found for struct `Asset` in the current scope HOT 1
- Is there a way to encrypt embedded file? Maybe before/after hooks? HOT 10
- A feature analogous to debug-embed, but for WASM? HOT 2
- Debug builds more lenient when loading relative paths
- `RustEmbed` derive macro is susceptible to naming collisions HOT 2
- rust-embed is tainted with MPL-2 via option-ext HOT 1
- low compilation performance when embeding large folder even though having excludes. HOT 1
- Unable to read symbolic link in debug mode HOT 4
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.