File tree 4 files changed +22
-12
lines changed 4 files changed +22
-12
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ use crate::Builder;
20
20
#[ cfg( doc) ]
21
21
use crate :: env;
22
22
23
- /// Create a new temporary directory.
23
+ /// Create a new temporary directory. Also see [`tempdir_in`].
24
24
///
25
25
/// The `tempdir` function creates a directory in the file system and returns a
26
26
/// [`TempDir`]. The directory will be automatically deleted when the `TempDir`'s
@@ -67,7 +67,7 @@ pub fn tempdir() -> io::Result<TempDir> {
67
67
TempDir :: new ( )
68
68
}
69
69
70
- /// Create a new temporary directory in a specific directory.
70
+ /// Create a new temporary directory in a specific directory. Also see [`tempdir`].
71
71
///
72
72
/// The `tempdir_in` function creates a directory in the specified directory
73
73
/// and returns a [`TempDir`].
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ use crate::Builder;
19
19
20
20
mod imp;
21
21
22
- /// Create a new temporary file.
22
+ /// Create a new temporary file. Also see [`tempfile_in`].
23
23
///
24
24
/// The file will be created in the location returned by [`env::temp_dir()`].
25
25
///
@@ -52,7 +52,7 @@ pub fn tempfile() -> io::Result<File> {
52
52
tempfile_in ( env:: temp_dir ( ) )
53
53
}
54
54
55
- /// Create a new temporary file in the specified directory.
55
+ /// Create a new temporary file in the specified directory. Also see [`tempfile`].
56
56
///
57
57
/// # Security
58
58
///
Original file line number Diff line number Diff line change 1
- //! Temporary files and directories.
1
+ //! This is a library for creating temporary files and directories that are automatically deleted
2
+ //! when no longer referenced (i.e., on drop).
2
3
//!
3
- //! - Use the [`tempfile()`] function for temporary files
4
- //! - Use the [`tempdir()`] function for temporary directories.
4
+ //! - Use [`tempfile()`] when you need a real [`std::fs::File`] but don't need to refer to it
5
+ //! by-path.
6
+ //! - Use [`NamedTempFile::new()`] when you need a _named_ temporary file that can be refered to its
7
+ //! path.
8
+ //! - Use [`tempdir()`] when you need a temporary directory that will be recursively deleted on drop.
9
+ //! - Use [`spooled_tempfile()`] when you need an in-memory buffer that will ultimately be backed by
10
+ //! a temporary file if it gets too large.
5
11
//!
6
12
//! # Design
7
13
//!
8
14
//! This crate provides several approaches to creating temporary files and directories.
9
15
//! [`tempfile()`] relies on the OS to remove the temporary file once the last handle is closed.
10
16
//! [`TempDir`] and [`NamedTempFile`] both rely on Rust destructors for cleanup.
11
17
//!
12
- //! When choosing between the temporary file variants, prefer `tempfile`
13
- //! unless you either need to know the file's path or to be able to persist it.
14
- //!
15
18
//! ## Resource Leaking
16
19
//!
17
20
//! `tempfile` will (almost) never fail to cleanup temporary resources. However `TempDir` and
Original file line number Diff line number Diff line change @@ -22,13 +22,20 @@ pub struct SpooledTempFile {
22
22
inner : SpooledData ,
23
23
}
24
24
25
- /// Create a new spooled temporary file .
25
+ /// Create a new [`SpooledTempFile`]. Also see [`spooled_tempfile_in`] .
26
26
///
27
27
/// # Security
28
28
///
29
29
/// This variant is secure/reliable in the presence of a pathological temporary
30
30
/// file cleaner.
31
31
///
32
+ /// # Backing Storage
33
+ ///
34
+ /// By default, the underlying temporary file will be created in your operating system's temporary
35
+ /// file directory which is _often_ an in-memory filesystem. You may want to consider using
36
+ /// [`spooled_tempfile_in`] instead, passing a storage-backed filesystem (e.g., `/var/tmp` on
37
+ /// Linux).
38
+ ///
32
39
/// # Resource Leaking
33
40
///
34
41
/// The temporary file will be automatically removed by the OS when the last
@@ -60,7 +67,7 @@ pub fn spooled_tempfile(max_size: usize) -> SpooledTempFile {
60
67
61
68
/// Construct a new [`SpooledTempFile`], backed by a file in the specified directory. Use this when,
62
69
/// e.g., you need the temporary file to be backed by a specific filesystem (e.g., when your default
63
- /// temporary directory is in-memory).
70
+ /// temporary directory is in-memory). Also see [`spooled_tempfile`].
64
71
///
65
72
/// **NOTE:** The specified path isn't checked until the temporary file is "rolled over" into a real
66
73
/// temporary file. If the specified directory isn't writable, writes to the temporary file will
You can’t perform that action at this time.
0 commit comments