Skip to main content

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#![cfg_attr(target_os = "wasi", doc = "```no_run")]
15#![cfg_attr(not(target_os = "wasi"), doc = "```ignore (needs wasi)")]
16//! use std::fs::File;
17//! use std::os::wasi::prelude::*;
18//!
19//! fn main() -> std::io::Result<()> {
20//!     let f = File::create("foo.txt")?;
21//!     let fd = f.as_raw_fd();
22//!
23//!     // use fd with native WASI bindings
24//!
25//!     Ok(())
26//! }
27//! ```
28//!
29//! [`OsStr`]: crate::ffi::OsStr
30//! [`OsString`]: crate::ffi::OsString
31
32#![cfg_attr(not(target_env = "p2"), stable(feature = "rust1", since = "1.0.0"))]
33#![cfg_attr(target_env = "p2", unstable(feature = "wasip2", issue = "none"))]
34#![forbid(unsafe_op_in_unsafe_fn)]
35#![doc(cfg(target_os = "wasi"))]
36
37pub mod ffi;
38pub mod fs;
39pub mod io;
40
41#[cfg(all(target_os = "wasi", target_env = "p1"))]
42pub mod net;
43
44/// A prelude for conveniently writing platform-specific code.
45///
46/// Includes all extension traits, and some important type definitions.
47#[stable(feature = "rust1", since = "1.0.0")]
48pub mod prelude {
49    #[doc(no_inline)]
50    #[stable(feature = "rust1", since = "1.0.0")]
51    pub use super::ffi::{OsStrExt, OsStringExt};
52    #[doc(no_inline)]
53    #[stable(feature = "rust1", since = "1.0.0")]
54    pub use super::fs::FileTypeExt;
55    #[doc(no_inline)]
56    #[stable(feature = "rust1", since = "1.0.0")]
57    pub use super::fs::{DirEntryExt, FileExt, MetadataExt, OpenOptionsExt};
58    #[doc(no_inline)]
59    #[stable(feature = "rust1", since = "1.0.0")]
60    pub use super::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
61}