known_folders/lib.rs
1// src/lib.rs
2//
3// Copyright (c) 2023 Ryan Lopopolo <rjl@hyperbo.la>
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE> or
6// <http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT>
7// or <http://opensource.org/licenses/MIT>, at your option. All files in the
8// project carrying such notice may not be copied, modified, or distributed
9// except according to those terms.
10
11#![warn(clippy::all)]
12#![warn(clippy::pedantic)]
13#![warn(clippy::cargo)]
14#![allow(unknown_lints)]
15#![warn(missing_copy_implementations)]
16#![warn(missing_debug_implementations)]
17#![warn(missing_docs)]
18#![warn(rust_2018_idioms)]
19#![warn(trivial_casts, trivial_numeric_casts)]
20#![warn(unused_qualifications)]
21#![warn(variant_size_differences)]
22// Enable feature callouts in generated documentation:
23// https://doc.rust-lang.org/beta/unstable-book/language-features/doc-cfg.html
24//
25// This approach is borrowed from tokio.
26#![cfg_attr(docsrs, feature(doc_cfg))]
27
28//! Retrieves the full path of a known folder identified by the folder's
29//! **KNOWNFOLDERID** on Windows systems using `SHGetKnownFolderPath` and the
30//! [Known Folders] API.
31//!
32//! # Platform Support
33//!
34//! The Known Folders API first appeared in Windows Vista.
35//!
36//! Note that this crate is completely empty on non-Windows platforms.
37//!
38//! ## Linkage
39//!
40//! The Known Folders API is provided by Win32, which is linked into every
41//! binary on Windows platforms.
42//!
43//! # Examples
44//!
45#![cfg_attr(windows, doc = "```")]
46#![cfg_attr(not(windows), doc = "```compile_fail")]
47//! use known_folders::{get_known_folder_path, KnownFolder};
48//!
49//! let profile_dir = get_known_folder_path(KnownFolder::Profile);
50//! ```
51//!
52//! [Known Folders]: https://learn.microsoft.com/en-us/windows/win32/shell/known-folders
53
54#![doc(html_root_url = "https://docs.rs/known-folders/1.4.2")]
55
56// Ensure code blocks in `README.md` compile
57#[cfg(all(doctest, windows))]
58#[doc = include_str!("../README.md")]
59mod readme {}
60
61#[cfg(windows)]
62#[allow(clippy::too_many_lines)]
63mod win;
64
65#[cfg(windows)]
66pub use self::win::*;
67
68#[cfg(all(test, windows))]
69mod tests {
70 use super::*;
71
72 #[test]
73 fn it_works() {
74 let profile_dir = get_known_folder_path(KnownFolder::Profile).unwrap();
75 assert!(profile_dir.is_dir());
76 assert!(profile_dir.exists());
77 }
78}