cap_async_std/fs/mod.rs
1//! A capability-based filesystem API modeled after [`async_std::fs`].
2//!
3//! This corresponds to [`async_std::fs`].
4//!
5//! Instead of [`async_std::fs`'s free functions] and [`async_std::fs::File`]'s
6//! constructors which operate on bare paths, this crate has methods on [`Dir`]
7//! which operate on paths which must be relative to the directory.
8//!
9//! Where `async_std` says "the filesystem", this API says "a filesystem", as
10//! it doesn't assume that there's a single global filesystem namespace.
11//!
12//! Since all functions which expose raw file descriptors are `unsafe`, I/O
13//! handles in this API are unforgeable (unsafe code notwithstanding). This
14//! combined with a lack of absolute paths provides a natural capability-based
15//! interface.
16//!
17//! This crate uses the existing `async_std::path::Path` rather than having its
18//! own path type, however while `async_std::path::Path` is mostly just a pure
19//! datatype, it includes aliases for several `async_std::fs` functions. To
20//! preserve the capability-based interface, avoid using
21//! `async_std::path::Path`'s `canonicalize`, `read_link`, `read_dir`,
22//! `metadata`, and `symlink_metadata` functions.
23//!
24//! [`async_std::fs`'s free functions]: https://docs.rs/async-std/latest/async_std/fs/#functions
25
26mod dir;
27mod dir_entry;
28mod file;
29mod read_dir;
30
31pub use dir::Dir;
32pub use dir_entry::DirEntry;
33pub use file::File;
34pub use read_dir::ReadDir;
35
36// Re-export things from `cap_primitives` that we can use as-is.
37#[cfg(not(target_os = "wasi"))]
38pub use cap_primitives::fs::{DirBuilder, FileType, Metadata, OpenOptions, Permissions};
39
40// Re-export conditional types from `cap_primitives`.
41#[cfg(any(unix, target_os = "vxworks", all(windows, windows_file_type_ext)))]
42pub use cap_primitives::fs::FileTypeExt;
43#[cfg(unix)]
44pub use cap_primitives::fs::{DirBuilderExt, PermissionsExt};
45pub use cap_primitives::fs::{FileExt, MetadataExt, OpenOptionsExt};
46
47// Re-export things from `async_std` that we can use as-is.
48#[cfg(target_os = "wasi")]
49pub use async_std::fs::{DirBuilder, FileType, Metadata, OpenOptions, Permissions};