1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use crateimp;
/// A borrowed reference to the directory containing an
/// [`AtomicWriteFile`](crate::AtomicWriteFile).
///
/// This can be obtained via [`AtomicWriteFile::directory()`](crate::AtomicWriteFile::directory).
/// The purpose of this struct is to allow you to obtain the directory file descriptor, without
/// having to open it through a call to `open(2)`.
///
/// This struct supports only two operations:
/// - conversion to a borrowed directory file descriptor through
/// [`AsFd::as_fd()`](std::os::fd::AsFd::as_fd)
/// - conversion to a raw directory file descriptor through
/// [`AsRawFd::as_raw_fd()`](std::os::fd::AsRawFd::as_raw_fd)
///
/// Directory file descriptors are not available on all platforms. See
/// [`AtomicWriteFile::directory()`](crate::AtomicWriteFile::directory) for more details.
///
/// # Examples
///
/// ```
/// # fn main() -> std::io::Result<()> {
/// # let test_dir = option_env!("TEST_DIR").unwrap_or("target/test-files");
/// # std::fs::create_dir_all(&test_dir).expect("failed to create test dir");
/// # std::env::set_current_dir(test_dir).expect("failed to move to test dir");
/// # #[cfg(any(unix, target_os = "wasi"))]
/// use std::os::fd::AsFd;
/// use atomic_write_file::AtomicWriteFile;
///
/// let file = AtomicWriteFile::open("foo.txt")?;
/// if let Some(dir) = file.directory() {
/// # #[cfg(any(unix, target_os = "wasi"))]
/// let borrowed_fd = dir.as_fd();
/// # #[cfg(any(unix, target_os = "wasi"))]
/// println!("directory fd: {:?}", borrowed_fd);
/// # #[cfg(not(any(unix, target_os = "wasi")))]
/// # let _ = dir;
/// }
/// # Ok(())
/// # }
/// ```