cap_async_std/fs/mod.rs
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
//! A capability-based filesystem API modeled after [`async_std::fs`].
//!
//! This corresponds to [`async_std::fs`].
//!
//! Instead of [`async_std::fs`'s free functions] and [`async_std::fs::File`]'s
//! constructors which operate on bare paths, this crate has methods on [`Dir`]
//! which operate on paths which must be relative to the directory.
//!
//! Where `async_std` says "the filesystem", this API says "a filesystem", as
//! it doesn't assume that there's a single global filesystem namespace.
//!
//! Since all functions which expose raw file descriptors are `unsafe`, I/O
//! handles in this API are unforgeable (unsafe code notwithstanding). This
//! combined with a lack of absolute paths provides a natural capability-based
//! interface.
//!
//! This crate uses the existing `async_std::path::Path` rather than having its
//! own path type, however while `async_std::path::Path` is mostly just a pure
//! datatype, it includes aliases for several `async_std::fs` functions. To
//! preserve the capability-based interface, avoid using
//! `async_std::path::Path`'s `canonicalize`, `read_link`, `read_dir`,
//! `metadata`, and `symlink_metadata` functions.
//!
//! [`async_std::fs`'s free functions]: https://docs.rs/async-std/latest/async_std/fs/#functions
mod dir;
mod dir_entry;
mod file;
mod read_dir;
pub use dir::Dir;
pub use dir_entry::DirEntry;
pub use file::File;
pub use read_dir::ReadDir;
// Re-export things from `cap_primitives` that we can use as-is.
#[cfg(not(target_os = "wasi"))]
pub use cap_primitives::fs::{DirBuilder, FileType, Metadata, OpenOptions, Permissions};
// Re-export conditional types from `cap_primitives`.
#[cfg(any(unix, target_os = "vxworks", all(windows, windows_file_type_ext)))]
pub use cap_primitives::fs::FileTypeExt;
#[cfg(unix)]
pub use cap_primitives::fs::{DirBuilderExt, PermissionsExt};
pub use cap_primitives::fs::{FileExt, MetadataExt, OpenOptionsExt};
// Re-export things from `async_std` that we can use as-is.
#[cfg(target_os = "wasi")]
pub use async_std::fs::{DirBuilder, FileType, Metadata, OpenOptions, Permissions};