std/os/wasi/
mod.rs

1//! Platform-specific extensions to `std` for the WebAssembly System Interface (WASI).
2//!
3//! Provides access to platform-level information on WASI, and exposes
4//! WASI-specific functions that would otherwise be inappropriate as
5//! part of the core `std` library.
6//!
7//! It exposes more ways to deal with platform-specific strings (`OsStr`,
8//! `OsString`), allows to set permissions more granularly, extract low-level
9//! file descriptors from files and sockets, and has platform-specific helpers
10//! for spawning processes.
11//!
12//! # Examples
13//!
14//! ```no_run
15//! use std::fs::File;
16//! use std::os::wasi::prelude::*;
17//!
18//! fn main() -> std::io::Result<()> {
19//!     let f = File::create("foo.txt")?;
20//!     let fd = f.as_raw_fd();
21//!
22//!     // use fd with native WASI bindings
23//!
24//!     Ok(())
25//! }
26//! ```
27//!
28//! [`OsStr`]: crate::ffi::OsStr
29//! [`OsString`]: crate::ffi::OsString
30
31#![cfg_attr(not(target_env = "p2"), stable(feature = "rust1", since = "1.0.0"))]
32#![cfg_attr(target_env = "p2", unstable(feature = "wasip2", issue = "none"))]
33#![forbid(unsafe_op_in_unsafe_fn)]
34#![doc(cfg(target_os = "wasi"))]
35
36pub mod ffi;
37pub mod fs;
38pub mod io;
39
40#[cfg(all(target_os = "wasi", target_env = "p1"))]
41pub mod net;
42
43/// A prelude for conveniently writing platform-specific code.
44///
45/// Includes all extension traits, and some important type definitions.
46#[stable(feature = "rust1", since = "1.0.0")]
47pub mod prelude {
48    #[doc(no_inline)]
49    #[stable(feature = "rust1", since = "1.0.0")]
50    pub use super::ffi::{OsStrExt, OsStringExt};
51    #[doc(no_inline)]
52    #[stable(feature = "rust1", since = "1.0.0")]
53    pub use super::fs::FileTypeExt;
54    #[doc(no_inline)]
55    #[stable(feature = "rust1", since = "1.0.0")]
56    pub use super::fs::{DirEntryExt, FileExt, MetadataExt, OpenOptionsExt};
57    #[doc(no_inline)]
58    #[stable(feature = "rust1", since = "1.0.0")]
59    pub use super::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
60}