rust_util/
util_os.rs

1use std::env;
2use std::path::PathBuf;
3
4use crate::iff;
5
6pub fn is_macos() -> bool {
7    cfg!(target_os = "macos")
8}
9
10pub fn is_linux() -> bool {
11    cfg!(target_os = "linux")
12}
13
14pub fn is_macos_or_linux() -> bool {
15    is_macos() || is_linux()
16}
17
18pub fn get_user_home() -> Option<String> {
19    iff!(is_macos_or_linux(), env::var("HOME").ok(), None)
20}
21
22pub fn get_full_work_dir() -> Option<String> {
23    PathBuf::from(".").canonicalize().ok().and_then(|p| {
24        p.to_str().map(ToString::to_string)
25    })
26}