async_std_utp/
lib.rs

1//! Implementation of the [Micro Transport Protocol][spec].
2//!
3//! This library provides both a socket interface (`UtpSocket`) and a stream interface
4//! (`UtpStream`).
5//! I recommend that you use `UtpStream`, as it implements the `Read` and `Write`
6//! traits we all know (and love) from `std::io`, which makes it generally easier to work with than
7//! `UtpSocket`.
8//!
9//! [spec]: http://www.bittorrent.org/beps/bep_0029.html
10//!
11//! # Installation
12//!
13//! Ensure your `Cargo.toml` contains:
14//!
15//! ```toml
16//! [dependencies]
17//! utp = "*"
18//! ```
19//!
20//! # Examples
21//!
22//! ```no_run
23//!
24//! use async_std_utp::UtpStream;
25//! use async_std::prelude::*;
26//!
27//! # fn main() { async_std::task::block_on(async {
28//!     // Connect to an hypothetical local server running on port 8080
29//!     let addr = "127.0.0.1:8080";
30//!     let mut stream = UtpStream::connect(addr).await.expect("Error connecting to remote peer");
31//!
32//!     // Send a string
33//!     stream.write("Hi there!".as_bytes()).await.expect("Write failed");
34//!
35//!     // Close the stream
36//!     stream.close().await.expect("Error closing connection");
37//! # }); }
38//! ```
39//!
40//! Note that you can easily convert a socket to a stream using the `Into` trait, like so:
41//!
42//! ```no_run
43//! # fn main() { async_std::task::block_on(async {
44//! use async_std_utp::{UtpStream, UtpSocket};
45//! let socket = UtpSocket::bind("0.0.0.0:0").await.expect("Error binding socket");
46//! let stream: UtpStream = socket.into();
47//! # }); }
48//! ```
49
50#![deny(missing_docs)]
51// Optional features
52#![cfg_attr(feature = "clippy", feature(plugin))]
53#![cfg_attr(feature = "clippy", plugin(clippy))]
54#![cfg_attr(
55    feature = "clippy",
56    allow(
57        len_without_is_empty,
58        doc_markdown,
59        needless_return,
60        transmute_ptr_to_ref
61    )
62)]
63#![cfg_attr(feature = "unstable", feature(test))]
64
65// Public API
66pub use crate::socket::UtpListener;
67pub use crate::socket::UtpSocket;
68pub use crate::stream::UtpStream;
69
70mod bit_iterator;
71mod error;
72mod packet;
73mod socket;
74mod stream;
75mod time;
76mod util;