tempfile_fast/
lib.rs

1//! # tempfile-fast
2//!
3//! (Slightly) faster temporary files on Linux.
4//!
5//! ## Sponge
6//!
7//! A [`Sponge`] is a safe and efficient way to update a file in place.
8//!
9//! ### Example
10//!
11//! ```rust
12//! # use std::io::Write;
13//! let mut temp = tempfile_fast::Sponge::new_for("example.txt").unwrap();
14//! temp.write_all(b"hello").unwrap();
15//! temp.commit().unwrap();
16//! ```
17//!
18//! ## PersistableTempFile
19//!
20//! The raw [`PersistableTempFile`] is also available. However,
21//! You probably want to use the [`tempfile`] crate unless you have
22//! hit a known performance problem, or you only care about modern
23//! Linux. See [`README.md`] for more details.
24//!
25//! ### Example (raw)
26//!
27//! ```rust,no_run
28//! # use std::io::Write;
29//! let mut temp = tempfile_fast::PersistableTempFile::new_in("/var/lib/foo").unwrap();
30//! temp.write_all(b"hello").unwrap();
31//! temp.persist_noclobber("/var/lib/foo/bar").unwrap();
32//! ```
33//!
34//! [`Sponge`]: struct.Sponge.html
35//! [`PersistableTempFile`]: enum.PersistableTempFile.html
36//! [`tempfile`]: https://crates.io/crates/tempfile
37//! [`README.md`]: https://github.com/FauxFaux/tempfile-fast-rs/blob/master/README.md
38
39#[cfg(target_os = "linux")]
40mod linux;
41
42#[cfg(not(target_os = "linux"))]
43mod linux {
44    use std::fs;
45    use std::io;
46    use std::path::Path;
47
48    #[inline]
49    pub fn create_nonexclusive_tempfile_in<P>(_dir: P) -> io::Result<fs::File> {
50        Err(io::ErrorKind::InvalidInput.into())
51    }
52
53    #[inline]
54    pub fn link_at<P: AsRef<Path>>(_what: &fs::File, _dest: P) -> io::Result<()> {
55        Err(io::ErrorKind::InvalidData.into())
56    }
57}
58
59mod persistable;
60mod sponge;
61
62pub use crate::persistable::PersistError;
63pub use crate::persistable::PersistableTempFile;
64pub use sponge::Sponge;