PowerTools/backend/src/utility.rs
Derek J. Clark 5d2937af6f
Multiplatform Dev (#52)
* Use environment home instead of hard coding home_path

* Fix Makefile

* Use PathBuf instead of format. Catch else fore /tmp/ default directory

* Restore logpath for deployment. Resolve warning from copy() not having err handled.

* Undo add #[cfg(debug_assertions)] in wrong place.
2022-11-29 00:04:03 +00:00

31 lines
832 B
Rust

use std::fmt::Display;
//use std::sync::{LockResult, MutexGuard};
pub fn unwrap_maybe_fatal<T: Sized, E: Display>(result: Result<T, E>, message: &str) -> T {
match result {
Ok(x) => x,
Err(e) => {
log::error!("{}: {}", message, e);
panic!("{}: {}", message, e);
}
}
}
/*pub fn unwrap_lock<'a, T: Sized>(
result: LockResult<MutexGuard<'a, T>>,
lock_name: &str,
) -> MutexGuard<'a, T> {
match result {
Ok(x) => x,
Err(e) => {
log::error!("Failed to acquire {} lock: {}", lock_name, e);
panic!("Failed to acquire {} lock: {}", lock_name, e);
}
}
}*/
pub fn settings_dir() -> std::path::PathBuf {
usdpl_back::api::dirs::home()
.unwrap_or_else(|| "/tmp/".into())
.join(".config/powertools/")
}