homedir

Crates.iohomedir
lib.rshomedir
version0.3.4
sourcesrc
created_at2023-08-13 00:02:38.245948
updated_at2024-10-01 01:50:51.734423
descriptionA crate to help get the home directory of any user on a system.
homepagehttps://jamespetersen.ca/homedir
repositoryhttps://github.com/ljtpetersen/homedir
max_upload_size
id943047
size50,446
James Petersen (ljtpetersen)

documentation

README

homedir   Build Status latest version docs passing

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, home and 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.

If all that is necessary is the home directory of the user executing this process, then other crates may be better options, such as directories. As well, using the home directory to find the documents, downloads, pictures, etc. directories may not be accurate.

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 getpwnam_r(3), getpwuid_r(3), and getuid(2) functions. As well, special care is necessary for Windows programs which use the COM library in other places. See the "For Windows Users" section in the crate documentation for more details.

Usage

This crate is on crates.io and can be used by executing cargo add homedir or adding the following to the dependencies in your Cargo.toml file.

[dependencies]
homedir = "0.3.4"

Features

  • windows-coinitialize -- This is enabled by default. On Windows, call CoInitializeEx if CoCreateInstance returns CO_E_NOTINITIALIZED. See the "For Windows Users" section of the documentation for details about CoInitializeEx.

The full documentation of the crate, including examples, is available on the docs.rs page.

Licensing

Licensed under either of

at your option.

Contribution

Unless you explicitly 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 and Credits

Copyright (C) 2023-2024 James Petersen m@jamespetersen.ca.

In version 0.3.0, the wmi-rs crate was referenced when writing the homedir::windows::UserIdentifier::to_home function, though there may not be any resemblance now. Nevertheless, I felt it was important to properly credit them, hence I included this statement here. The referenced repository is also licensed under APACHE and MIT, which are included in this repository.

Commit count: 35

cargo fmt