futures_net/lib.rs
1//! # Async network TCP, UDP, UDS
2//!
3//! The types are designed to closely follow the APIs of the
4//! analogous types in `std::net` in `Asychronous` versions.
5//!
6//! # Examples
7//! __TCP Server__
8//! ```rust,no_run
9//! use futures_net::{TcpListener, TcpStream, runtime::Runtime};
10//! use futures::prelude::*;
11//!
12//! async fn say_hello(mut stream: TcpStream) {
13//! stream.write_all(b"Shall I hear more, or shall I speak at this?").await;
14//! }
15//!
16//! #[futures_net::main]
17//! async fn main() -> Result<(), Box<dyn std::error::Error + 'static>> {
18//! let socket_addr = "127.0.0.1:8080".parse()?;
19//! let mut listener = TcpListener::bind(&socket_addr)?;
20//! let mut incoming = listener.incoming();
21//!
22//! // accept connections and process them serially
23//! while let Some(stream) = incoming.next().await {
24//! say_hello(stream?).await;
25//! }
26//! Ok(())
27//! }
28//! ```
29//! __TCP Client__
30//! ```rust,no_run
31//! use std::error::Error;
32//! use futures::prelude::*;
33//! use futures_net::{TcpListener, TcpStream, runtime::Runtime};
34//!
35//! #[futures_net::main]
36//! async fn main() -> Result<(), Box<dyn Error + 'static>> {
37//! let socket_addr = "127.0.0.1:8080".parse()?;
38//! let mut buffer = vec![];
39//! let mut stream = TcpStream::connect(&socket_addr).await?;
40//!
41//! stream.read(&mut buffer).await?;
42//! println!("{:?}", buffer);
43//! Ok(())
44//! }
45//! ```
46
47#![warn(
48 rust_2018_idioms,
49 unreachable_pub,
50 missing_debug_implementations,
51 missing_docs
52)]
53#![allow(
54 warnings,
55 missing_docs,
56 type_alias_bounds,
57 clippy::type_complexity,
58 clippy::borrow_interior_mutable_const,
59 clippy::needless_doctest_main,
60 clippy::too_many_arguments,
61 clippy::new_without_default
62)]
63#[deny(clippy::drop_copy)]
64
65#[cfg(feature = "macro")]
66#[doc(inline)]
67pub use futures_net_macro::{main, test};
68
69pub mod driver;
70pub mod runtime;
71pub mod tcp;
72pub mod udp;
73pub mod uds;
74
75#[doc(inline)]
76pub use crate::tcp::{TcpListener, TcpStream};
77#[doc(inline)]
78pub use crate::udp::UdpSocket;
79#[doc(inline)]
80pub use crate::uds::{UnixDatagram, UnixListener, UnixStream};