diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f63aac..6fb28db 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## CHANGELOG +### v0.7.4 (2019-11-12) + +* Imporve **expand** performance. + ### v0.7.3 (2019-11-08) * New **expand** function #15 diff --git a/Cargo.toml b/Cargo.toml index 1969753..568abec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "envmnt" -version = "0.7.3" +version = "0.7.4" authors = ["Sagie Gur-Ari "] description = "Environment variables utility functions." license = "Apache-2.0" diff --git a/docs/api/envmnt/types/enum.ExpansionType.html b/docs/api/envmnt/types/enum.ExpansionType.html index b3026e0..6afdea0 100644 --- a/docs/api/envmnt/types/enum.ExpansionType.html +++ b/docs/api/envmnt/types/enum.ExpansionType.html @@ -12,7 +12,7 @@ UnixBrackets

Unix brackets environment style, for example: ${MY_ENV}

Unix

All unix supported styles

Windows

Windows environment style, for example: %MY_ENV%

-
OS

Current OS supported styles (UnixAll/Windows)

+
OS

Current OS supported styles (Unix/Windows)

All

All supported styles for all platforms

Trait Implementations

impl PartialEq<ExpansionType> for ExpansionType[src]

#[must_use] diff --git a/docs/api/search-index.js b/docs/api/search-index.js index 6d5e325..15a558d 100644 --- a/docs/api/search-index.js +++ b/docs/api/search-index.js @@ -1,5 +1,5 @@ var N=null,E="",T="t",U="u",searchIndex={}; var R=["envmnt","osstr","string","asref","Returns false if environment variable value if falsy. The…","option","Returns true if the provided environment variable is…","Sets the provided string vector as an environment variable.","Returns the requested environment variable as a string…","listoptions","Sets all the provided env key/value pairs.","indexmap","envmnterror","Parses the provided env file and loads all environment…","expandoptions","Creates and returns a new instance.","ListOptions","Get/Set list options","ExpansionType","Expansion Type - unix/windows style","ExpandOptions","Expand options","envmnt::types","result","to_owned","clone_into","try_from","try_into","borrow_mut","type_id","expansiontype","formatter"]; -searchIndex["envmnt"]={"doc":R[0],"i":[[5,"exists",R[0],"Returns true environment variable is defined.",N,[[[R[1]],[R[3],[R[1]]]],["bool"]]],[5,"remove",E,"Removes the provided environment variable.",N,[[[R[1]],[R[3],[R[1]]]]]],[5,"get_remove",E,"Removes the provided environment variable and returns its…",N,[[[R[1]],[R[3],[R[1]]]],[[R[2]],[R[5],[R[2]]]]]],[5,"remove_all",E,"Removes all provided environment variables.",N,[[["vec"]]]],[5,"get_or",E,"Returns the environment variable value or if is not…",N,[[[R[1]],["str"],[R[3],[R[1]]]],[R[2]]]],[5,"get_or_panic",E,"Returns the environment variable value. If the variable is…",N,[[[R[1]],[R[3],[R[1]]]],[R[2]]]],[5,"get_any",E,"Returns the first environment variable found.",N,[[["vec"],["str"]],[R[2]]]],[5,"is_or",E,R[4],N,[[[R[1]],["bool"],[R[3],[R[1]]]],["bool"]]],[5,"is",E,R[4],N,[[[R[1]],[R[3],[R[1]]]],["bool"]]],[5,"set",E,"Sets the environment variable value.",N,[[[R[1]],[R[3],[R[1]]]]]],[5,"set_bool",E,"Sets the environment variable with a true/false value as…",N,[[[R[1]],["bool"],[R[3],[R[1]]]]]],[5,"set_optional",E,"Sets the environment variable if the provided option…",N,[[[R[5]],[R[1]],[R[3],[R[1]]]],["bool"]]],[5,"get_set",E,"Sets the environment variable value and returns the…",N,[[[R[1]],[R[3],[R[1]]]],[[R[2]],[R[5],[R[2]]]]]],[5,"vars",E,"Returns all environment variables as a vector.",N,[[],["vec"]]],[5,"is_equal",E,R[6],N,[[[R[1]],["str"],[R[3],[R[1]]]],["bool"]]],[5,"contains",E,R[6],N,[[[R[1]],["str"],[R[3],[R[1]]]],["bool"]]],[5,"contains_ignore_case",E,R[6],N,[[[R[1]],["str"],[R[3],[R[1]]]],["bool"]]],[5,"set_list",E,R[7],N,[[[R[1]],["vec"],[R[3],[R[1]]]]]],[5,"get_list",E,R[8],N,[[[R[1]],[R[3],[R[1]]]],[["vec",[R[2]]],[R[5],["vec"]]]]],[5,"set_list_with_options",E,R[7],N,[[["vec"],[R[3],[R[1]]],[R[9]],[R[1]]]]],[5,"get_list_with_options",E,R[8],N,[[[R[1]],[R[9]],[R[3],[R[1]]]],[["vec",[R[2]]],[R[5],["vec"]]]]],[5,"set_all",E,R[10],N,[[[R[11]]]]],[5,"evaluate_and_set_all",E,R[10],N,[[["f"],[R[11]]]]],[5,"is_any_exists",E,"Returns true if any of environment variables is defined.",N,[[["vec"]],["bool"]]],[5,"is_all_exists",E,"Returns true if all of environment variables are defined.",N,[[["vec"]],["bool"]]],[5,"load_file",E,R[13],N,[[["str"]],[[R[12]],[R[23],[R[12]]]]]],[5,"evaluate_and_load_file",E,R[13],N,[[["f"],["str"]],[[R[12]],[R[23],[R[12]]]]]],[5,"parse_file",E,"Parses the provided env file and returns its content as a…",N,[[["str"]],[[R[12]],[R[23],[R[11],R[12]]],[R[11],[R[2],R[2]]]]]],[5,"expand",E,"Expands the provided string value by replacing the…",N,[[[R[14]],["str"],[R[5],[R[14]]]],[R[2]]]],[0,"types",E,"types",N,N],[3,R[16],R[22],R[17],N,N],[12,"separator",E,"The separator used to merge/split the values",0,N],[12,"ignore_empty",E,"if true, empty list will not be set and empty string will…",0,N],[3,R[20],E,R[21],N,N],[12,"expansion_type",E,"The expansion type (unix/windows/...)",1,N],[12,"default_to_empty",E,"if true (default), empty variables will be replaced with…",1,N],[4,R[18],E,R[19],N,N],[13,"UnixPrefix",E,"Unix prefix environment style, for example: $MY_ENV",2,N],[13,"UnixBrackets",E,"Unix brackets environment style, for example: ${MY_ENV}",2,N],[13,"Unix",E,"All unix supported styles",2,N],[13,"Windows",E,"Windows environment style, for example: %MY_ENV%",2,N],[13,"OS",E,"Current OS supported styles (UnixAll/Windows)",2,N],[13,"All",E,"All supported styles for all platforms",2,N],[11,"new",E,R[15],0,[[],[R[9]]]],[11,"new",E,R[15],1,[[],[R[14]]]],[11,"clone_with_expansion_type",E,"Clones and modifies the expansion type",1,[[[R[14]],[R[30]]],[R[14]]]],[6,R[16],R[0],R[17],N,N],[6,R[18],E,R[19],N,N],[6,R[20],E,R[21],N,N],[11,"from",R[22],E,0,[[[T]],[T]]],[11,"into",E,E,0,[[],[U]]],[11,R[24],E,E,0,[[["self"]],[T]]],[11,R[25],E,E,0,[[[T],["self"]]]],[11,R[26],E,E,0,[[[U]],[R[23]]]],[11,R[27],E,E,0,[[],[R[23]]]],[11,R[28],E,E,0,[[["self"]],[T]]],[11,"borrow",E,E,0,[[["self"]],[T]]],[11,R[29],E,E,0,[[["self"]],["typeid"]]],[11,"from",E,E,1,[[[T]],[T]]],[11,"into",E,E,1,[[],[U]]],[11,R[24],E,E,1,[[["self"]],[T]]],[11,R[25],E,E,1,[[[T],["self"]]]],[11,R[26],E,E,1,[[[U]],[R[23]]]],[11,R[27],E,E,1,[[],[R[23]]]],[11,R[28],E,E,1,[[["self"]],[T]]],[11,"borrow",E,E,1,[[["self"]],[T]]],[11,R[29],E,E,1,[[["self"]],["typeid"]]],[11,"from",E,E,2,[[[T]],[T]]],[11,"into",E,E,2,[[],[U]]],[11,R[24],E,E,2,[[["self"]],[T]]],[11,R[25],E,E,2,[[[T],["self"]]]],[11,R[26],E,E,2,[[[U]],[R[23]]]],[11,R[27],E,E,2,[[],[R[23]]]],[11,R[28],E,E,2,[[["self"]],[T]]],[11,"borrow",E,E,2,[[["self"]],[T]]],[11,R[29],E,E,2,[[["self"]],["typeid"]]],[11,"eq",E,E,2,[[[R[30]],["self"]],["bool"]]],[11,"clone",E,E,0,[[["self"]],[R[9]]]],[11,"clone",E,E,2,[[["self"]],[R[30]]]],[11,"clone",E,E,1,[[["self"]],[R[14]]]],[11,"fmt",E,E,0,[[[R[31]],["self"]],[R[23]]]],[11,"fmt",E,E,2,[[[R[31]],["self"]],[R[23]]]],[11,"fmt",E,E,1,[[[R[31]],["self"]],[R[23]]]]],"p":[[3,R[16]],[3,R[20]],[4,R[18]]]}; +searchIndex["envmnt"]={"doc":R[0],"i":[[5,"exists",R[0],"Returns true environment variable is defined.",N,[[[R[1]],[R[3],[R[1]]]],["bool"]]],[5,"remove",E,"Removes the provided environment variable.",N,[[[R[1]],[R[3],[R[1]]]]]],[5,"get_remove",E,"Removes the provided environment variable and returns its…",N,[[[R[1]],[R[3],[R[1]]]],[[R[2]],[R[5],[R[2]]]]]],[5,"remove_all",E,"Removes all provided environment variables.",N,[[["vec"]]]],[5,"get_or",E,"Returns the environment variable value or if is not…",N,[[[R[1]],["str"],[R[3],[R[1]]]],[R[2]]]],[5,"get_or_panic",E,"Returns the environment variable value. If the variable is…",N,[[[R[1]],[R[3],[R[1]]]],[R[2]]]],[5,"get_any",E,"Returns the first environment variable found.",N,[[["vec"],["str"]],[R[2]]]],[5,"is_or",E,R[4],N,[[[R[1]],["bool"],[R[3],[R[1]]]],["bool"]]],[5,"is",E,R[4],N,[[[R[1]],[R[3],[R[1]]]],["bool"]]],[5,"set",E,"Sets the environment variable value.",N,[[[R[1]],[R[3],[R[1]]]]]],[5,"set_bool",E,"Sets the environment variable with a true/false value as…",N,[[[R[1]],["bool"],[R[3],[R[1]]]]]],[5,"set_optional",E,"Sets the environment variable if the provided option…",N,[[[R[5]],[R[1]],[R[3],[R[1]]]],["bool"]]],[5,"get_set",E,"Sets the environment variable value and returns the…",N,[[[R[1]],[R[3],[R[1]]]],[[R[2]],[R[5],[R[2]]]]]],[5,"vars",E,"Returns all environment variables as a vector.",N,[[],["vec"]]],[5,"is_equal",E,R[6],N,[[[R[1]],["str"],[R[3],[R[1]]]],["bool"]]],[5,"contains",E,R[6],N,[[[R[1]],["str"],[R[3],[R[1]]]],["bool"]]],[5,"contains_ignore_case",E,R[6],N,[[[R[1]],["str"],[R[3],[R[1]]]],["bool"]]],[5,"set_list",E,R[7],N,[[[R[1]],["vec"],[R[3],[R[1]]]]]],[5,"get_list",E,R[8],N,[[[R[1]],[R[3],[R[1]]]],[["vec",[R[2]]],[R[5],["vec"]]]]],[5,"set_list_with_options",E,R[7],N,[[["vec"],[R[3],[R[1]]],[R[9]],[R[1]]]]],[5,"get_list_with_options",E,R[8],N,[[[R[1]],[R[9]],[R[3],[R[1]]]],[["vec",[R[2]]],[R[5],["vec"]]]]],[5,"set_all",E,R[10],N,[[[R[11]]]]],[5,"evaluate_and_set_all",E,R[10],N,[[["f"],[R[11]]]]],[5,"is_any_exists",E,"Returns true if any of environment variables is defined.",N,[[["vec"]],["bool"]]],[5,"is_all_exists",E,"Returns true if all of environment variables are defined.",N,[[["vec"]],["bool"]]],[5,"load_file",E,R[13],N,[[["str"]],[[R[12]],[R[23],[R[12]]]]]],[5,"evaluate_and_load_file",E,R[13],N,[[["f"],["str"]],[[R[12]],[R[23],[R[12]]]]]],[5,"parse_file",E,"Parses the provided env file and returns its content as a…",N,[[["str"]],[[R[12]],[R[23],[R[11],R[12]]],[R[11],[R[2],R[2]]]]]],[5,"expand",E,"Expands the provided string value by replacing the…",N,[[[R[14]],["str"],[R[5],[R[14]]]],[R[2]]]],[0,"types",E,"types",N,N],[3,R[16],R[22],R[17],N,N],[12,"separator",E,"The separator used to merge/split the values",0,N],[12,"ignore_empty",E,"if true, empty list will not be set and empty string will…",0,N],[3,R[20],E,R[21],N,N],[12,"expansion_type",E,"The expansion type (unix/windows/...)",1,N],[12,"default_to_empty",E,"if true (default), empty variables will be replaced with…",1,N],[4,R[18],E,R[19],N,N],[13,"UnixPrefix",E,"Unix prefix environment style, for example: $MY_ENV",2,N],[13,"UnixBrackets",E,"Unix brackets environment style, for example: ${MY_ENV}",2,N],[13,"Unix",E,"All unix supported styles",2,N],[13,"Windows",E,"Windows environment style, for example: %MY_ENV%",2,N],[13,"OS",E,"Current OS supported styles (Unix/Windows)",2,N],[13,"All",E,"All supported styles for all platforms",2,N],[11,"new",E,R[15],0,[[],[R[9]]]],[11,"new",E,R[15],1,[[],[R[14]]]],[11,"clone_with_expansion_type",E,"Clones and modifies the expansion type",1,[[[R[14]],[R[30]]],[R[14]]]],[6,R[16],R[0],R[17],N,N],[6,R[18],E,R[19],N,N],[6,R[20],E,R[21],N,N],[11,"from",R[22],E,0,[[[T]],[T]]],[11,"into",E,E,0,[[],[U]]],[11,R[24],E,E,0,[[["self"]],[T]]],[11,R[25],E,E,0,[[[T],["self"]]]],[11,R[26],E,E,0,[[[U]],[R[23]]]],[11,R[27],E,E,0,[[],[R[23]]]],[11,R[28],E,E,0,[[["self"]],[T]]],[11,"borrow",E,E,0,[[["self"]],[T]]],[11,R[29],E,E,0,[[["self"]],["typeid"]]],[11,"from",E,E,1,[[[T]],[T]]],[11,"into",E,E,1,[[],[U]]],[11,R[24],E,E,1,[[["self"]],[T]]],[11,R[25],E,E,1,[[[T],["self"]]]],[11,R[26],E,E,1,[[[U]],[R[23]]]],[11,R[27],E,E,1,[[],[R[23]]]],[11,R[28],E,E,1,[[["self"]],[T]]],[11,"borrow",E,E,1,[[["self"]],[T]]],[11,R[29],E,E,1,[[["self"]],["typeid"]]],[11,"from",E,E,2,[[[T]],[T]]],[11,"into",E,E,2,[[],[U]]],[11,R[24],E,E,2,[[["self"]],[T]]],[11,R[25],E,E,2,[[[T],["self"]]]],[11,R[26],E,E,2,[[[U]],[R[23]]]],[11,R[27],E,E,2,[[],[R[23]]]],[11,R[28],E,E,2,[[["self"]],[T]]],[11,"borrow",E,E,2,[[["self"]],[T]]],[11,R[29],E,E,2,[[["self"]],["typeid"]]],[11,"eq",E,E,2,[[[R[30]],["self"]],["bool"]]],[11,"clone",E,E,0,[[["self"]],[R[9]]]],[11,"clone",E,E,2,[[["self"]],[R[30]]]],[11,"clone",E,E,1,[[["self"]],[R[14]]]],[11,"fmt",E,E,0,[[[R[31]],["self"]],[R[23]]]],[11,"fmt",E,E,2,[[[R[31]],["self"]],[R[23]]]],[11,"fmt",E,E,1,[[[R[31]],["self"]],[R[23]]]]],"p":[[3,R[16]],[3,R[20]],[4,R[18]]]}; initSearch(searchIndex);addSearchOptions(searchIndex); \ No newline at end of file diff --git a/docs/api/src/envmnt/environment.rs.html b/docs/api/src/envmnt/environment.rs.html index e2c51dc..9cbc57c 100644 --- a/docs/api/src/envmnt/environment.rs.html +++ b/docs/api/src/envmnt/environment.rs.html @@ -249,6 +249,10 @@ 249 250 251 +252 +253 +254 +255
 //! # environment
 //!
@@ -456,6 +460,10 @@
 }
 
 pub(crate) fn expand(value: &str, options: Option<ExpandOptions>) -> String {
+    if value.len() == 0 {
+        return value.to_string();
+    }
+
     let expand_options = match options {
         Some(value) => value,
         None => ExpandOptions::new(),
diff --git a/docs/api/src/envmnt/types.rs.html b/docs/api/src/envmnt/types.rs.html
index 138f2a1..0603d79 100644
--- a/docs/api/src/envmnt/types.rs.html
+++ b/docs/api/src/envmnt/types.rs.html
@@ -113,7 +113,7 @@
     Unix,
     /// Windows environment style, for example: %MY_ENV%
     Windows,
-    /// Current OS supported styles (UnixAll/Windows)
+    /// Current OS supported styles (Unix/Windows)
     OS,
     /// All supported styles for all platforms
     All,
diff --git a/src/environment.rs b/src/environment.rs
index bb3ad69..2c94754 100755
--- a/src/environment.rs
+++ b/src/environment.rs
@@ -204,6 +204,10 @@ pub(crate) fn get_list_with_options>(
 }
 
 pub(crate) fn expand(value: &str, options: Option) -> String {
+    if value.len() == 0 {
+        return value.to_string();
+    }
+
     let expand_options = match options {
         Some(value) => value,
         None => ExpandOptions::new(),
diff --git a/src/environment_test.rs b/src/environment_test.rs
index fbe7bec..b874479 100755
--- a/src/environment_test.rs
+++ b/src/environment_test.rs
@@ -558,6 +558,13 @@ fn get_list_with_options_multiple() {
     );
 }
 
+#[test]
+fn expand_empty_string() {
+    let output = expand("", None);
+
+    assert_eq!(output.len(), 0);
+}
+
 #[test]
 fn expand_unix_prefix_none() {
     let mut options = ExpandOptions::new();