diff --git a/CHANGELOG.md b/CHANGELOG.md index 6190aba..e82eb86 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## CHANGELOG +### v0.3.1 + +* Remove dependency on 'users' crate #10 + ### v0.3.0 (2021-09-13) * Support windows UNC paths diff --git a/Cargo.toml b/Cargo.toml index 12f440b..945653a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,9 +26,6 @@ include = [ [dependencies] rand = { version = "^0.8", optional = true } -[target.'cfg(not(windows))'.dependencies] -users = { version = "^0.11", optional = true } - [target.'cfg(windows)'.dependencies] dunce = "^1" @@ -37,7 +34,7 @@ doc-comment = "^0.3" [features] default = [] -temp-path = ["rand", "users"] +temp-path = ["rand"] [badges.codecov] branch = "master" diff --git a/src/path/temp_path.rs b/src/path/temp_path.rs index aecd9e8..0593251 100644 --- a/src/path/temp_path.rs +++ b/src/path/temp_path.rs @@ -4,9 +4,6 @@ use rand::{thread_rng, Rng}; use std::env; use std::iter; -#[cfg(not(windows))] -use users::get_current_username; - #[cfg(windows)] fn get_additional_temp_path() -> Option { None @@ -14,27 +11,26 @@ fn get_additional_temp_path() -> Option { #[cfg(not(windows))] fn get_additional_temp_path() -> Option { - let username = get_current_username(); - - match username { - Some(os_value) => match os_value.into_string() { - Ok(value) => Some(value), - Err(_) => None, - }, - None => None, - } + let random_string = get_random_string(); + let mut additional_path = env!("CARGO_PKG_NAME").to_string(); + additional_path.push('_'); + additional_path.push_str(&random_string); + Some(additional_path.to_string()) } -pub(crate) fn get(extension: &str) -> String { - let name = env!("CARGO_PKG_NAME"); - +fn get_random_string() -> String { let mut rng = thread_rng(); - let file_name: String = iter::repeat(()) + iter::repeat(()) .map(|()| rng.sample(Alphanumeric)) .map(char::from) .take(10) - .collect(); + .collect() +} + +pub(crate) fn get(extension: &str) -> String { + let name = env!("CARGO_PKG_NAME"); + let file_name = get_random_string(); let mut file_path = env::temp_dir(); match get_additional_temp_path() {