hf/lib.rs
1// SPDX-FileCopyrightText: 2024 Shun Sakai
2//
3// SPDX-License-Identifier: Apache-2.0 OR MIT
4
5//! The `hf` crate is a cross-platform library for manipulating [hidden files
6//! and directories].
7//!
8//! This crate supports both Unix and Windows. On Unix, hidden files and
9//! directories are files and directories that starts with a dot character
10//! (`.`). On Windows, hidden files and directories are files and directories
11//! with the hidden file attribute.
12//!
13//! # Examples
14//!
15//! ## On Unix
16//!
17//! ```
18//! # #[cfg(unix)]
19//! # {
20//! use std::fs::File;
21//!
22//! let temp_dir = tempfile::tempdir().unwrap();
23//! let temp_dir = temp_dir.path();
24//! let file_path = temp_dir.join("foo.txt");
25//! let hidden_file_path = hf::unix::hidden_file_name(&file_path).unwrap();
26//! assert_eq!(hidden_file_path, temp_dir.join(".foo.txt"));
27//! assert!(!file_path.exists());
28//! assert!(!hidden_file_path.exists());
29//!
30//! File::create(&file_path).unwrap();
31//! assert!(file_path.exists());
32//! assert!(!hidden_file_path.exists());
33//!
34//! hf::hide(&file_path).unwrap();
35//! assert!(!file_path.exists());
36//! assert!(hidden_file_path.exists());
37//!
38//! hf::show(&hidden_file_path).unwrap();
39//! assert!(file_path.exists());
40//! assert!(!hidden_file_path.exists());
41//! # }
42//! ```
43//!
44//! ## On Windows
45//!
46//! ```
47//! # #[cfg(windows)]
48//! # {
49//! use std::fs::File;
50//!
51//! let temp_dir = tempfile::tempdir().unwrap();
52//! let file_path = temp_dir.path().join("foo.txt");
53//! assert!(!file_path.exists());
54//!
55//! File::create(&file_path).unwrap();
56//! assert!(file_path.exists());
57//! assert_eq!(hf::is_hidden(&file_path).unwrap(), false);
58//!
59//! hf::hide(&file_path).unwrap();
60//! assert!(file_path.exists());
61//! assert_eq!(hf::is_hidden(&file_path).unwrap(), true);
62//!
63//! hf::show(&file_path).unwrap();
64//! assert!(file_path.exists());
65//! assert_eq!(hf::is_hidden(file_path).unwrap(), false);
66//! # }
67//! ```
68//!
69//! [hidden files and directories]: https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory
70
71#![doc(html_root_url = "https://docs.rs/hf/0.6.0/")]
72#![cfg_attr(docsrs, feature(doc_cfg))]
73// Lint levels of rustc.
74#![deny(missing_docs)]
75
76mod ops;
77mod platform;
78
79pub use crate::ops::{hide, is_hidden, show};
80#[cfg(unix)]
81pub use crate::platform::unix;