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
50
51
52
//! Tubes
//!
//! Provides tube functionality like the python library [pwntools](https://github.com/Gallopsled/pwntools).
//!
//! The methods are provided in the struct [`Tube`](tubes::Tube)
//!
//! Example:
//!
//! ```rust
//! use io_tubes::tubes::Tube;
//! use std::io;
//!
//! #[tokio::main]
//! async fn demo() -> io::Result<()> {
//! let mut p = Tube::process("/usr/bin/cat")?;
//!
//! // "Hello World!" will be automatically converted to `&[u8]`
//! // Alternatively, you can explicitly use b"Hello World!" if it contains invalid UTF-8.
//! p.send("Hello World!").await?;
//!
//! // You can use any type that implements `AsRef<[u8]>`
//! let output = p.recv_until(b"World".to_vec()).await?;
//! assert_eq!(output, b"Hello World");
//! Ok(())
//! }
//!
//! demo();
//! ```
//!
//! Any type that implement [`AsyncRead`](tokio::io::AsyncRead) + [`AsyncWrite`](tokio::io::AsyncWrite) can
//! make use of [`Tube::new`](crate::tubes::Tube::new) to create a new tube.
//!
//! ```rust
//! use io_tubes::tubes::{Listener, Tube};
//! use std::io;
//! use tokio::net::TcpStream;
//!
//! #[tokio::main]
//! async fn create_remote() -> io::Result<()> {
//! let l = Listener::bind("0.0.0.0:1337").await?;
//!
//! // The followings are equivalent `Tube<BufReader<TcpStream>>`.
//! let mut p = Tube::remote("127.0.0.1:1337").await?;
//! let mut p = Tube::new(TcpStream::connect("127.0.0.1:1337").await?);
//!
//! Ok(())
//! }
//!
//! create_remote();
//! ```