1
0
mirror of https://github.com/jht5945/rust_util.git synced 2025-12-27 23:40:05 +08:00

add read_str_to_lines, tests, fix bug

This commit is contained in:
2020-05-05 13:27:21 +08:00
parent 66d3540b65
commit a672cdfa45
4 changed files with 90 additions and 5 deletions

View File

@@ -1,6 +1,10 @@
use std::env;
pub fn is_env_on(var: &str) -> bool {
env::var(var).map(|v| v.to_lowercase()).map(|v| vec!["true", "yes", "1"].iter().any(|x| x == &v)).unwrap_or(false)
env::var(var).ok().map(|val| is_on(&val)).unwrap_or(false)
}
pub fn is_on(val: &str) -> bool {
let lower_val = val.to_lowercase();
vec!["true", "yes", "1"].iter().any(|x| *x == lower_val)
}