socketpair/
lib.rs

1//! Cross-platform socketpair functionality
2//!
3//! A socketpair stream is a bidirectional bytestream. The `socketpair_stream`
4//! function creates a pair of `SocketpairStream` objects connected to opposite
5//! ends of a stream, and both can be written to and read from.
6//!
7//! ```rust
8//! use socketpair::socketpair_stream;
9//! use std::io::{self, Read, Write};
10//! use std::thread;
11//!
12//! fn main() -> anyhow::Result<()> {
13//!     let (mut a, mut b) = socketpair_stream()?;
14//!
15//!     let _t = thread::spawn(move || -> io::Result<()> { writeln!(a, "hello world") });
16//!
17//!     let mut buf = String::new();
18//!     b.read_to_string(&mut buf)?;
19//!     assert_eq!(buf, "hello world\n");
20//!
21//!     Ok(())
22//! }
23//! ```
24
25#![deny(missing_docs)]
26#![cfg_attr(can_vector, feature(can_vector))]
27#![cfg_attr(all(unix, unix_socket_peek), feature(unix_socket_peek))]
28#![cfg_attr(write_all_vectored, feature(write_all_vectored))]
29
30#[cfg(not(windows))]
31mod rustix;
32#[cfg(all(unix, feature = "async-std"))]
33mod unix_async_std;
34#[cfg(all(unix, feature = "tokio"))]
35mod unix_tokio;
36#[cfg(windows)]
37mod windows;
38#[cfg(all(windows, feature = "async-std"))]
39mod windows_async_std;
40#[cfg(all(windows, feature = "tokio"))]
41mod windows_tokio;
42
43#[cfg(unix)]
44pub use crate::rustix::{socketpair_seqpacket, socketpair_stream, SocketpairStream};
45#[cfg(all(unix, feature = "async-std"))]
46pub use crate::unix_async_std::{async_std_socketpair_stream, AsyncStdSocketpairStream};
47#[cfg(all(unix, feature = "tokio"))]
48pub use crate::unix_tokio::{tokio_socketpair_stream, TokioSocketpairStream};
49#[cfg(windows)]
50pub use crate::windows::{socketpair_seqpacket, socketpair_stream, SocketpairStream};
51#[cfg(all(windows, feature = "async-std"))]
52pub use crate::windows_async_std::{async_std_socketpair_stream, AsyncStdSocketpairStream};
53#[cfg(all(windows, feature = "tokio"))]
54pub use crate::windows_tokio::{tokio_socketpair_stream, TokioSocketpairStream};