io_tubes/lib.rs
1//! Tubes
2//!
3//! Provides tube functionality like the python library [pwntools](https://github.com/Gallopsled/pwntools).
4//!
5//! The methods are provided in the struct [`Tube`](tubes::Tube)
6//!
7//! Example:
8//!
9//! ```rust
10//! use io_tubes::tubes::Tube;
11//! use std::io;
12//!
13//! #[tokio::main]
14//! async fn demo() -> io::Result<()> {
15//! let mut p = Tube::process("/usr/bin/cat")?;
16//!
17//! // "Hello World!" will be automatically converted to `&[u8]`
18//! // Alternatively, you can explicitly use b"Hello World!" if it contains invalid UTF-8.
19//! p.send("Hello World!").await?;
20//!
21//! // You can use any type that implements `AsRef<[u8]>`
22//! let output = p.recv_until(b"World".to_vec()).await?;
23//! assert_eq!(output, b"Hello World");
24//! Ok(())
25//! }
26//!
27//! demo();
28//! ```
29//!
30//! Any type that implement [`AsyncRead`](tokio::io::AsyncRead) + [`AsyncWrite`](tokio::io::AsyncWrite) can
31//! make use of [`Tube::new`](crate::tubes::Tube::new) to create a new tube.
32//!
33//! ```rust
34//! use io_tubes::tubes::{Listener, Tube};
35//! use std::io;
36//! use tokio::net::TcpStream;
37//!
38//! #[tokio::main]
39//! async fn create_remote() -> io::Result<()> {
40//! let l = Listener::bind("0.0.0.0:1337").await?;
41//!
42//! // The followings are equivalent `Tube<BufReader<TcpStream>>`.
43//! let mut p = Tube::remote("127.0.0.1:1337").await?;
44//! let mut p = Tube::new(TcpStream::connect("127.0.0.1:1337").await?);
45//!
46//! Ok(())
47//! }
48//!
49//! create_remote();
50//! ```
51pub mod tubes;
52mod utils;