|0.2.1||Aug 27, 2023|
|0.1.0||Aug 13, 2023|
#317 in Configuration
204 downloads per month
Used in archie-cli
This crate exists to provide a portable method to getting any user's home
directory. The API is rather simple: there are two main functions,
get_my_home. The former can get the home directory
of any user provided you have their username. The latter can get the home
directory of the user executing this process.
This crate aims to work on both Windows and Unix systems. However,
Unix systems do not have a unified API. This crate may not work
on Unix systems which do not have the
This crate is on crates.io and can be used by executing
cargo add homedir
or adding the following to the dependencies in your
[dependencies] homedir = "0.2.1"
Get the process' user's home directory.
use homedir::get_my_home; // This assumes that the process' user has "/home/jpetersen" as home directory. assert_eq!( std::path::Path::new("/home/jpetersen"), get_my_home().unwrap().unwrap().as_path() );
Get an arbitrary user's home directory.
use homedir::get_home; // This assumes there is a user named `Administrator` which has // `C:\Users\Administrator` as a home directory. assert_eq!( std::path::Path::new("C:\\Users\\Administrator"), get_home("Administrator").unwrap().unwrap().as_path() ); assert!(get_home("NonExistentUser").unwrap().is_none());
The full documentation of the crate is available on the docs.rs page.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitely state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Feel free to put a copyright header in your name in any files you contribute to.
Copyright (C) 2023 James Petersen firstname.lastname@example.org.