simple_fs/common/
system.rs

1use crate::{Error, Result, SPath};
2
3/// Returns the home directory of the current user as an `SPath`.
4pub fn home_dir() -> Result<SPath> {
5	#[allow(deprecated)]
6	let path = std::env::home_dir().ok_or(Error::HomeDirNotFound)?;
7	SPath::from_std_path(path)
8}
9
10// region:    --- Tests
11
12#[cfg(test)]
13mod tests {
14	type Result<T> = core::result::Result<T, Box<dyn std::error::Error>>;
15
16	use super::*;
17
18	#[test]
19	fn test_common_system_home_dir_simple() -> Result<()> {
20		// -- Exec
21		let home = home_dir()?;
22
23		// -- Check
24		assert!(home.exists(), "Home directory should exist");
25		assert!(home.is_absolute(), "Home directory should be an absolute path");
26
27		Ok(())
28	}
29}
30
31// endregion: --- Tests