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#![cfg_attr(docsrs, feature(doc_alias))]
28
29//! Retrieves the full path of a known folder identified by the folder's
30//! **KNOWNFOLDERID** on Windows systems using `SHGetKnownFolderPath` and the
31//! [Known Folders] API.
32//!
33//! # Platform Support
34//!
35//! The Known Folders API first appeared in Windows Vista.
36//!
37//! Note that this crate is completely empty on non-Windows platforms.
38//!
39//! ## Linkage
40//!
41//! The Known Folders API is provided by Win32, which is linked into every
42//! binary on Windows platforms.
43//!
44//! # Examples
45//!
46#![cfg_attr(windows, doc = "```")]
47#![cfg_attr(not(windows), doc = "```compile_fail")]
48//! use known_folders::{get_known_folder_path, KnownFolder};
49//!
50//! let profile_dir = get_known_folder_path(KnownFolder::Profile);
51//! ```
52//!
53//! [Known Folders]: https://learn.microsoft.com/en-us/windows/win32/shell/known-folders
54
55#![doc(html_root_url = "https://docs.rs/known-folders/1.2.0")]
56
57// Ensure code blocks in `README.md` compile
58#[cfg(all(doctest, windows))]
59#[doc = include_str!("../README.md")]
60mod readme {}
61
62#[cfg(windows)]
63#[allow(clippy::too_many_lines)]
64mod win;
65
66#[cfg(windows)]
67pub use self::win::*;
68
69#[cfg(all(test, windows))]
70mod tests {
71 use super::*;
72
73 #[test]
74 fn it_works() {
75 let profile_dir = get_known_folder_path(KnownFolder::Profile).unwrap();
76 assert!(profile_dir.is_dir());
77 assert!(profile_dir.exists());
78 }
79}