camino_tempfile_ext/lib.rs
1// Copyright (c) The camino-tempfile Contributors
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4#![warn(missing_docs)]
5#![cfg_attr(doc_cfg, feature(doc_auto_cfg))]
6
7//! Quality-of-life extensions for [`camino-tempfile`].
8//!
9//! camino-tempfile-ext provides utilities for:
10//!
11//! * Creating files and directories within a [`Utf8TempDir`].
12//! * Asserting on file and directory contents.
13//!
14//! This crate is geared primarily towards testing and development, but it may
15//! be of use in production environments as well.
16//!
17//! # Examples
18//!
19//! ```
20//! use camino_tempfile_ext::prelude::*;
21//!
22//! // Create a temporary directory.
23//! let dir = Utf8TempDir::new().unwrap();
24//!
25//! // Create a nested file within this directory. Creation of intermediate
26//! // directories is automatic.
27//! let file = dir.child("foo/bar/baz.txt");
28//! file.write_str("Hello, world!").unwrap();
29//!
30//! // Assert on the file's contents (requires the assert feature)
31//! # #[cfg(feature = "assert")]
32//! file.assert("Hello, world!");
33//! ```
34//!
35//! # Features
36//!
37//! - **assert**: Enable assertions on file and directory contents. *Not enabled by default.*
38//! - **assert-color**: Enable colored output for assertions: enables **assert**. *Not enabled by default.*
39//!
40//! # Minimum supported Rust version (MSRV)
41//!
42//! camino-tempfile-ext's MSRV is **Rust 1.74**. At any time, at least the last
43//! 6 months of Rust releases will be supported.
44//!
45//! # Credits
46//!
47//! Portions of camino-tempfile-ext have been adapted from [`assert_fs`] (thank
48//! you to the upstream maintainers!). If you need to work with
49//! [`std::path::Path`] rather than [`camino::Utf8Path`], check out
50//! [`assert_fs`].
51//!
52//! Upstream code is used under the terms of the MIT and Apache 2.0 licenses.
53//!
54//! [`camino-tempfile`]: camino_tempfile
55//! [`assert_fs`]: https://crates.io/crates/assert_fs
56//! [`Utf8TempDir`]: camino_tempfile::Utf8TempDir
57
58#[cfg(feature = "assert")]
59pub mod assert;
60#[cfg(feature = "assert")]
61mod color;
62pub mod fixture;
63
64/// Extension traits and types that are useful to have available.
65pub mod prelude {
66 #[cfg(feature = "assert")]
67 pub use crate::assert::PathAssert;
68 pub use crate::fixture::{
69 FileTouch, FileWriteBin, FileWriteFile, FileWriteStr, PathChild, PathCopy, PathCreateDir,
70 SymlinkToDir, SymlinkToFile,
71 };
72 pub use camino_tempfile::{NamedUtf8TempFile, Utf8TempDir};
73}
74
75// Re-exports of public dependencies.
76pub use camino_tempfile;
77#[cfg(feature = "assert")]
78pub use predicates_core;