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

add locate_file

This commit is contained in:
2020-05-04 20:54:16 +08:00
parent 7bfffc7bb6
commit 66d3540b65
2 changed files with 11 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "rust_util" name = "rust_util"
version = "0.2.3" version = "0.2.4"
authors = ["Hatter Jiang <jht5945@gmail.com>"] authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018" edition = "2018"
description = "Hatter's Rust Util" description = "Hatter's Rust Util"

View File

@@ -13,6 +13,16 @@ use super::{
XResult, XResult,
}; };
pub fn locate_file(files: &[String]) -> Option<PathBuf> {
for f in files {
match PathBuf::from(&resolve_file_path(f)) {
pb if pb.is_file() => return Some(pb),
_ => (),
}
}
None
}
pub fn get_home_str() -> Option<String> { pub fn get_home_str() -> Option<String> {
iff!(util_os::is_macos_or_linux(), env::var("HOME").ok(), None) iff!(util_os::is_macos_or_linux(), env::var("HOME").ok(), None)
} }