4 releases (2 breaking)

0.3.4 Oct 1, 2024
0.3.3 Jul 5, 2024
0.2.1 Aug 27, 2023
0.1.0 Aug 13, 2023

#16 in Configuration

Download history 9555/week @ 2024-08-20 9079/week @ 2024-08-27 9598/week @ 2024-09-03 9230/week @ 2024-09-10 7639/week @ 2024-09-17 9964/week @ 2024-09-24 9704/week @ 2024-10-01 11593/week @ 2024-10-08 12349/week @ 2024-10-15 12983/week @ 2024-10-22 14074/week @ 2024-10-29 16368/week @ 2024-11-05 16763/week @ 2024-11-12 21861/week @ 2024-11-19 20809/week @ 2024-11-26 21509/week @ 2024-12-03

83,762 downloads per month
Used in 58 crates (30 directly)

MIT/Apache

35KB
424 lines

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 (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.

Dependencies

~1–37MB
~564K SLoC