~repos /rust-embed

#rust#proc-macro#http

git clone https://pyrossh.dev/repos/rust-embed.git

rust macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.


34299eb1 Peter John

4 years ago
Merge pull request #156 from ay524/use-globset
Files changed (3) hide show
  1. readme.md +2 -2
  2. utils/Cargo.toml +3 -3
  3. utils/src/lib.rs +9 -5
readme.md CHANGED
@@ -104,7 +104,7 @@ Compress each file when embedding into the binary. Compression is done via [`inc
104
104
 
105
105
  ### `include-exclude`
106
106
  Filter files to be embedded with multiple `#[include = "*.txt"]` and `#[exclude = "*.jpg"]` attributes.
107
- Matching is done on relative file paths, via [`glob`].
107
+ Matching is done on relative file paths, via [`globset`].
108
108
  `exclude` attributes have higher priority than `include` attributes.
109
109
  Example:
110
110
 
@@ -177,4 +177,4 @@ Go Rusketeers!
177
177
  The power is yours!
178
178
 
179
179
  [`include-flate`]: https://crates.io/crates/include-flate
180
- [`glob`]: https://crates.io/crates/glob
180
+ [`globset`]: https://crates.io/crates/globset
utils/Cargo.toml CHANGED
@@ -15,10 +15,10 @@ edition = "2018"
15
15
  walkdir = "2.3.1"
16
16
  sha2 = "0.9"
17
17
 
18
- [dependencies.glob]
18
+ [dependencies.globset]
19
- version = "0.3.0"
19
+ version = "0.4.8"
20
20
  optional = true
21
21
 
22
22
  [features]
23
23
  debug-embed = []
24
- include-exclude = ["glob"]
24
+ include-exclude = ["globset"]
utils/src/lib.rs CHANGED
@@ -19,13 +19,15 @@ pub fn is_path_included(_path: &str, _includes: &[&str], _excludes: &[&str]) ->
19
19
 
20
20
  #[cfg(feature = "include-exclude")]
21
21
  pub fn is_path_included(rel_path: &str, includes: &[&str], excludes: &[&str]) -> bool {
22
- use glob::Pattern;
22
+ use globset::Glob;
23
23
 
24
24
  // ignore path matched by exclusion pattern
25
25
  for exclude in excludes {
26
+ let pattern = Glob::new(exclude)
26
- let pattern = Pattern::new(exclude).unwrap_or_else(|_| panic!("invalid exclude pattern '{}'", exclude));
27
+ .unwrap_or_else(|_| panic!("invalid exclude pattern '{}'", exclude))
28
+ .compile_matcher();
27
29
 
28
- if pattern.matches(rel_path) {
30
+ if pattern.is_match(rel_path) {
29
31
  return false;
30
32
  }
31
33
  }
@@ -37,9 +39,11 @@ pub fn is_path_included(rel_path: &str, includes: &[&str], excludes: &[&str]) ->
37
39
 
38
40
  // accept path if matched by inclusion pattern
39
41
  for include in includes {
42
+ let pattern = Glob::new(include)
40
- let pattern = Pattern::new(include).unwrap_or_else(|_| panic!("invalid include pattern '{}'", include));
43
+ .unwrap_or_else(|_| panic!("invalid include pattern '{}'", include))
44
+ .compile_matcher();
41
45
 
42
- if pattern.matches(rel_path) {
46
+ if pattern.is_match(rel_path) {
43
47
  return true;
44
48
  }
45
49
  }