Module cache_buster::hash [−][src]
Structs
+Module cache_buster::hash [−][src]
Structs
Buster | |
BusterBuilder | Builder for |
Enums
BusterBuilderError | Error type for BusterBuilder diff --git a/cache_buster/hash/struct.Buster.html b/cache_buster/hash/struct.Buster.html index 16f895f..8dba7c4 100644 --- a/cache_buster/hash/struct.Buster.html +++ b/cache_buster/hash/struct.Buster.html @@ -1,7 +1,7 @@Struct cache_buster:: |
Files |
Struct cache_buster::map::Files [−][src]
pub struct Files { +Struct cache_buster::
map:: [−][src]Files - Fields
map: HashMap<String, String>
Implementations
impl Files
[src]
pub fn get<'a>(&'a self, path: &'a str) -> Option<&'a String>
[src]
pub fn add(&mut self, k: String, v: String) -> Result<(), &'static str>
[src]Trait Implementations
impl Clone for Files
[src]
fn clone(&self) -> Files
[src]Returns a copy of the value. Read more
+ Fieldsmap: HashMap<String, String>
Implementations
impl Files
[src]
pub fn new(base_dir: &str) -> Self
[src]
pub fn get<'a>(&'a self, path: &'a str) -> Option<&'a String>
[src]
pub fn add(&mut self, k: String, v: String) -> Result<(), &'static str>
[src]
pub fn to_env(&self)
[src]
pub fn load() -> Self
[src]Trait Implementations
impl Clone for Files
[src]
fn clone(&self) -> Files
[src]Returns a copy of the value. Read more
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]Performs copy-assignment from
-source
. Read more
impl Debug for Files
[src]
fn fmt(&self, f: &mut Formatter<'_>) -> Result
[src]Formats the value using the given formatter. Read more
-
impl Default for Files
[src]Auto Trait Implementations
impl RefUnwindSafe for Files
[src]
impl Send for Files
[src]
impl Sync for Files
[src]
impl Unpin for Files
[src]
impl UnwindSafe for Files
[src]Blanket Implementations
impl<T> Any for T where
[src]
T: 'static + ?Sized,
impl Debug for Files
[src]
fn fmt(&self, f: &mut Formatter<'_>) -> Result
[src]Formats the value using the given formatter. Read more
+
impl Default for Files
[src]
impl<'de> Deserialize<'de> for Files
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
[src]
__D: Deserializer<'de>,Deserialize this value from the given Serde deserializer. Read more
+
impl PartialEq<Files> for Files
[src]
fn eq(&self, other: &Files) -> bool
[src]This method tests for
+self
andother
values to be equal, and is used +by==
. Read more
fn ne(&self, other: &Files) -> bool
[src]This method tests for
+!=
.
impl Serialize for Files
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
[src]
__S: Serializer,Serialize this value into the given Serde serializer. Read more
+
impl StructuralPartialEq for Files
[src]Auto Trait Implementations
impl RefUnwindSafe for Files
[src]
impl Send for Files
[src]
impl Sync for Files
[src]
impl Unpin for Files
[src]
impl UnwindSafe for Files
[src]Blanket Implementations
impl<T> Any for T where
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
-
impl<T> From<T> for T
[src]
impl<T> DeserializeOwned for T where
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be
Self
impl<T> ToOwned for T where
[src]
T: Clone,
type Owned = T
diff --git a/src/cache_buster/map.rs.html b/src/cache_buster/map.rs.html index 49e3d15..9760071 100644 --- a/src/cache_buster/map.rs.html +++ b/src/cache_buster/map.rs.html @@ -1,82 +1,147 @@The resulting type after obtaining ownership.
diff --git a/implementors/core/cmp/trait.PartialEq.js b/implementors/core/cmp/trait.PartialEq.js new file mode 100644 index 0000000..79929cc --- /dev/null +++ b/implementors/core/cmp/trait.PartialEq.js @@ -0,0 +1,3 @@ +(function() {var implementors = {}; +implementors["cache_buster"] = [{"text":"impl PartialEq<Files> for Files","synthetic":false,"types":["cache_buster::map::Files"]}]; +if (window.register_implementors) {window.register_implementors(implementors);} else {window.pending_implementors = implementors;}})() \ No newline at end of file diff --git a/implementors/core/marker/trait.StructuralPartialEq.js b/implementors/core/marker/trait.StructuralPartialEq.js new file mode 100644 index 0000000..3dd6a9b --- /dev/null +++ b/implementors/core/marker/trait.StructuralPartialEq.js @@ -0,0 +1,3 @@ +(function() {var implementors = {}; +implementors["cache_buster"] = [{"text":"impl StructuralPartialEq for Files","synthetic":false,"types":["cache_buster::map::Files"]}]; +if (window.register_implementors) {window.register_implementors(implementors);} else {window.pending_implementors = implementors;}})() \ No newline at end of file diff --git a/implementors/serde/de/trait.Deserialize.js b/implementors/serde/de/trait.Deserialize.js new file mode 100644 index 0000000..1527ca9 --- /dev/null +++ b/implementors/serde/de/trait.Deserialize.js @@ -0,0 +1,3 @@ +(function() {var implementors = {}; +implementors["cache_buster"] = [{"text":"impl<'de> Deserialize<'de> for Files","synthetic":false,"types":["cache_buster::map::Files"]}]; +if (window.register_implementors) {window.register_implementors(implementors);} else {window.pending_implementors = implementors;}})() \ No newline at end of file diff --git a/implementors/serde/ser/trait.Serialize.js b/implementors/serde/ser/trait.Serialize.js new file mode 100644 index 0000000..9e22888 --- /dev/null +++ b/implementors/serde/ser/trait.Serialize.js @@ -0,0 +1,3 @@ +(function() {var implementors = {}; +implementors["cache_buster"] = [{"text":"impl Serialize for Files","synthetic":false,"types":["cache_buster::map::Files"]}]; +if (window.register_implementors) {window.register_implementors(implementors);} else {window.pending_implementors = implementors;}})() \ No newline at end of file diff --git a/search-index.js b/search-index.js index 32e2e30..7e42643 100644 --- a/search-index.js +++ b/search-index.js @@ -1,4 +1,4 @@ var searchIndex = JSON.parse('{\ -"cache_buster":{"doc":"","i":[[0,"hash","cache_buster","",null,null],[3,"Buster","cache_buster::hash","",null,null],[3,"BusterBuilder","","Builder forBuster
.",null,null],[11,"source","","",0,[[["into",8],["string",3]]]],[11,"mime_types","","",0,[[["mime",3],["vec",3]]]],[11,"result","","",0,[[["into",8],["string",3]]]],[11,"copy","","",0,[[["bool",15]]]],[11,"follow_links","","",0,[[["bool",15]]]],[11,"build","","Builds a newBuster
.",0,[[],[["result",4],["busterbuildererror",4],["buster",3]]]],[4,"BusterBuilderError","","Error type for BusterBuilder",null,null],[13,"UninitializedField","","Uninitialized field",1,null],[13,"ValidationError","","Custom validation error",1,null],[11,"init","","",2,[[],[["result",4],["error",3]]]],[11,"try_hash","","",2,[[],[["result",4],["files",3],["error",3]]]],[11,"hash","","",2,[[],[["result",4],["files",3],["error",3]]]],[0,"map","cache_buster","",null,null],[3,"Files","cache_buster::map","",null,null],[12,"map","","",3,null],[11,"get","","",3,[[["str",15]],[["string",3],["option",4]]]],[11,"add","","",3,[[["string",3]],[["result",4],["str",15]]]],[11,"from","cache_buster::hash","",2,[[]]],[11,"into","","",2,[[]]],[11,"to_owned","","",2,[[]]],[11,"clone_into","","",2,[[]]],[11,"borrow","","",2,[[]]],[11,"borrow_mut","","",2,[[]]],[11,"try_from","","",2,[[],["result",4]]],[11,"try_into","","",2,[[],["result",4]]],[11,"type_id","","",2,[[],["typeid",3]]],[11,"from","","",0,[[]]],[11,"into","","",0,[[]]],[11,"to_owned","","",0,[[]]],[11,"clone_into","","",0,[[]]],[11,"borrow","","",0,[[]]],[11,"borrow_mut","","",0,[[]]],[11,"try_from","","",0,[[],["result",4]]],[11,"try_into","","",0,[[],["result",4]]],[11,"type_id","","",0,[[],["typeid",3]]],[11,"from","","",1,[[]]],[11,"into","","",1,[[]]],[11,"to_string","","",1,[[],["string",3]]],[11,"borrow","","",1,[[]]],[11,"borrow_mut","","",1,[[]]],[11,"try_from","","",1,[[],["result",4]]],[11,"try_into","","",1,[[],["result",4]]],[11,"type_id","","",1,[[],["typeid",3]]],[11,"from","cache_buster::map","",3,[[]]],[11,"into","","",3,[[]]],[11,"to_owned","","",3,[[]]],[11,"clone_into","","",3,[[]]],[11,"borrow","","",3,[[]]],[11,"borrow_mut","","",3,[[]]],[11,"try_from","","",3,[[],["result",4]]],[11,"try_into","","",3,[[],["result",4]]],[11,"type_id","","",3,[[],["typeid",3]]],[11,"from","cache_buster::hash","",1,[[["uninitializedfielderror",3]]]],[11,"from","","",1,[[["string",3]]]],[11,"clone","","",2,[[],["buster",3]]],[11,"clone","","",0,[[],["busterbuilder",3]]],[11,"clone","cache_buster::map","",3,[[],["files",3]]],[11,"default","cache_buster::hash","",0,[[]]],[11,"default","cache_buster::map","",3,[[],["files",3]]],[11,"fmt","cache_buster::hash","",2,[[["formatter",3]],["result",6]]],[11,"fmt","","",1,[[["formatter",3]],["result",6]]],[11,"fmt","cache_buster::map","",3,[[["formatter",3]],["result",6]]],[11,"fmt","cache_buster::hash","",1,[[["formatter",3]],["result",6]]]],"p":[[3,"BusterBuilder"],[4,"BusterBuilderError"],[3,"Buster"],[3,"Files"]]}\ +"cache_buster":{"doc":"","i":[[0,"hash","cache_buster","",null,null],[3,"Buster","cache_buster::hash","",null,null],[3,"BusterBuilder","","Builder forBuster
.",null,null],[11,"source","","",0,[[["string",3],["into",8]]]],[11,"mime_types","","",0,[[["vec",3],["mime",3]]]],[11,"result","","",0,[[["string",3],["into",8]]]],[11,"copy","","",0,[[["bool",15]]]],[11,"follow_links","","",0,[[["bool",15]]]],[11,"build","","Builds a newBuster
.",0,[[],[["busterbuildererror",4],["buster",3],["result",4]]]],[4,"BusterBuilderError","","Error type for BusterBuilder",null,null],[13,"UninitializedField","","Uninitialized field",1,null],[13,"ValidationError","","Custom validation error",1,null],[11,"init","","",2,[[],[["result",4],["error",3]]]],[11,"try_hash","","",2,[[],[["error",3],["result",4],["files",3]]]],[11,"hash","","",2,[[],[["error",3],["result",4],["files",3]]]],[0,"map","cache_buster","",null,null],[3,"Files","cache_buster::map","",null,null],[12,"map","","",3,null],[11,"new","","",3,[[["str",15]]]],[11,"get","","",3,[[["str",15]],[["option",4],["string",3]]]],[11,"add","","",3,[[["string",3]],[["result",4],["str",15]]]],[11,"to_env","","",3,[[]]],[11,"load","","",3,[[]]],[11,"from","cache_buster::hash","",2,[[]]],[11,"into","","",2,[[]]],[11,"to_owned","","",2,[[]]],[11,"clone_into","","",2,[[]]],[11,"borrow","","",2,[[]]],[11,"borrow_mut","","",2,[[]]],[11,"try_from","","",2,[[],["result",4]]],[11,"try_into","","",2,[[],["result",4]]],[11,"type_id","","",2,[[],["typeid",3]]],[11,"from","","",0,[[]]],[11,"into","","",0,[[]]],[11,"to_owned","","",0,[[]]],[11,"clone_into","","",0,[[]]],[11,"borrow","","",0,[[]]],[11,"borrow_mut","","",0,[[]]],[11,"try_from","","",0,[[],["result",4]]],[11,"try_into","","",0,[[],["result",4]]],[11,"type_id","","",0,[[],["typeid",3]]],[11,"from","","",1,[[]]],[11,"into","","",1,[[]]],[11,"to_string","","",1,[[],["string",3]]],[11,"borrow","","",1,[[]]],[11,"borrow_mut","","",1,[[]]],[11,"try_from","","",1,[[],["result",4]]],[11,"try_into","","",1,[[],["result",4]]],[11,"type_id","","",1,[[],["typeid",3]]],[11,"from","cache_buster::map","",3,[[]]],[11,"into","","",3,[[]]],[11,"to_owned","","",3,[[]]],[11,"clone_into","","",3,[[]]],[11,"borrow","","",3,[[]]],[11,"borrow_mut","","",3,[[]]],[11,"try_from","","",3,[[],["result",4]]],[11,"try_into","","",3,[[],["result",4]]],[11,"type_id","","",3,[[],["typeid",3]]],[11,"from","cache_buster::hash","",1,[[["uninitializedfielderror",3]]]],[11,"from","","",1,[[["string",3]]]],[11,"clone","","",2,[[],["buster",3]]],[11,"clone","","",0,[[],["busterbuilder",3]]],[11,"clone","cache_buster::map","",3,[[],["files",3]]],[11,"default","cache_buster::hash","",0,[[]]],[11,"default","cache_buster::map","",3,[[],["files",3]]],[11,"eq","","",3,[[["files",3]],["bool",15]]],[11,"ne","","",3,[[["files",3]],["bool",15]]],[11,"fmt","cache_buster::hash","",2,[[["formatter",3]],["result",6]]],[11,"fmt","","",1,[[["formatter",3]],["result",6]]],[11,"fmt","cache_buster::map","",3,[[["formatter",3]],["result",6]]],[11,"fmt","cache_buster::hash","",1,[[["formatter",3]],["result",6]]],[11,"serialize","cache_buster::map","",3,[[],["result",4]]],[11,"deserialize","","",3,[[],["result",4]]]],"p":[[3,"BusterBuilder"],[4,"BusterBuilderError"],[3,"Buster"],[3,"Files"]]}\ }'); addSearchOptions(searchIndex);initSearch(searchIndex); \ No newline at end of file diff --git a/src/cache_buster/hash.rs.html b/src/cache_buster/hash.rs.html index a4b9a6e..005eea8 100644 --- a/src/cache_buster/hash.rs.html +++ b/src/cache_buster/hash.rs.html @@ -252,6 +252,9 @@ 249 250 251 +252 +253 +254diff --git a/src/cache_buster/lib.rs.html b/src/cache_buster/lib.rs.html index d8fa53a..736128f 100644 --- a/src/cache_buster/lib.rs.html +++ b/src/cache_buster/lib.rs.html @@ -75,8 +75,8 @@ //! ``` pub mod hash; -pub mod map; pub use hash::BusterBuilder; +pub mod map; pub use map::Files;/* * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> @@ -332,12 +335,10 @@ self.copy(path, &new_name); let (source, destination) = self.gen_map(path, &&new_name); - file_map - .add( - source.to_str().unwrap().into(), - destination.to_str().unwrap().into(), - ) - .unwrap(); + let _ = file_map.add( + source.to_str().unwrap().into(), + destination.to_str().unwrap().into(), + ); } } } @@ -376,12 +377,10 @@ ); self.copy(path, &new_name); let (source, destination) = self.gen_map(path, &&new_name); - file_map - .add( - source.to_str().unwrap().into(), - destination.to_str().unwrap().into(), - ) - .unwrap(); + let _ = file_map.add( + source.to_str().unwrap().into(), + destination.to_str().unwrap().into(), + ); } } } @@ -443,7 +442,7 @@ } #[cfg(test)] -mod tests { +pub mod tests { use super::*; #[test] @@ -473,6 +472,7 @@ assert_eq!(src.exists(), dest.exists()); } + cleanup(&config); } #[test] @@ -494,7 +494,7 @@ .unwrap(); config.init().unwrap(); - let mut files = config.try_hash().unwrap(); + let mut files = config.hash().unwrap(); for (k, v) in files.map.drain() { let src = Path::new(&k); @@ -502,6 +502,12 @@ assert_eq!(src.exists(), dest.exists()); } + + cleanup(&config); + } + + pub fn cleanup(config: &Buster) { + let _ = fs::remove_dir_all(&config.result); } }
map.rs - source 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141/* * Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net> @@ -86,14 +151,26 @@ */ use std::collections::HashMap; +use std::env; -#[derive(Debug, Default, Clone)] +use serde::{Deserialize, Serialize}; + +const ENV_VAR_NAME: &str = "CACHE_BUSTER_FILE_MAP"; + +#[derive(Debug, PartialEq, Default, Clone, Serialize, Deserialize)] pub struct Files { pub map: HashMap<String, String>, base_dir: String, } impl Files { + pub fn new(base_dir: &str) -> Self { + Files { + map: HashMap::default(), + base_dir: base_dir.into(), + } + } + pub fn get<'a>(&'a self, path: &'a str) -> Option<&'a String> { self.map.get(path) } @@ -106,10 +183,32 @@ Ok(()) } } + + pub fn to_env(&self) { + println!( + "cargo:rustc-env={}={}", + ENV_VAR_NAME, + serde_json::to_string(&self).unwrap() + ); + + // needed for testing load() + // if the above statement fails(println), then something's broken + // with the rust compiler. So not really worried about that. + #[cfg(test)] + env::set_var(ENV_VAR_NAME, serde_json::to_string(&self).unwrap()); + } + + pub fn load() -> Self { + let env = env::var(ENV_VAR_NAME) + .expect("unable to read env var, might be a bug in lib. Please report on GitHub"); + let res: Files = serde_json::from_str(&env).unwrap(); + res + } } #[cfg(test)] mod tests { + use crate::hash::tests::cleanup; use crate::hash::*; use super::*; @@ -144,6 +243,7 @@ assert!(!file_exists("dist/log-out.svg", &files)); assert!(!file_exists("dist/a/b/c/d/s/d/svg/credit-card.svg", &files)); + cleanup(&config); } fn file_exists(path: &str, files: &Files) -> bool { @@ -153,6 +253,36 @@ false } } + + #[test] + fn load_works() { + let types = vec![ + mime::IMAGE_PNG, + mime::IMAGE_SVG, + mime::IMAGE_JPEG, + mime::IMAGE_GIF, + ]; + + let config = BusterBuilder::default() + .source("./dist") + .result("/tmp/prod3") + .mime_types(types) + .copy(true) + .follow_links(true) + .build() + .unwrap(); + + config.init().unwrap(); + let files = config.hash().unwrap(); + + files.to_env(); + + let x = Files::load(); + + assert_eq!(files, x); + + cleanup(&config); + } }