Skip to content

Commit 07e30ae

Browse files
casimircarllerche
authored andcommitted
net: rework tokio_tcp and tokio_udp re-exports (#548)
This patch keeps the primary net types in `tokio::net` and moves secondary types to a protocol specific submodules. Primary types are the ones that users are most likely to name (`TcpStream`, `TcpListener`, `UdpSocket`, ...) Secondary types are the operation futures.
1 parent 69d90ac commit 07e30ae

File tree

1 file changed

+65
-34
lines changed

1 file changed

+65
-34
lines changed

src/net.rs

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,85 @@
1-
//! TCP/UDP bindings for `tokio`.
1+
//! TCP/UDP/Unix bindings for `tokio`.
22
//!
3-
//! This module contains the TCP/UDP networking types, similar to the standard
3+
//! This module contains the TCP/UDP/Unix networking types, similar to the standard
44
//! library, which can be used to implement networking protocols.
55
//!
6-
//! # TCP
6+
//! # Organization
77
//!
8-
//! Connecting to an address, via TCP, can be done using [`TcpStream`]'s
9-
//! [`connect`] method, which returns [`ConnectFuture`]. `ConnectFuture`
10-
//! implements a future which returns a `TcpStream`.
8+
//! * [`TcpListener`] and [`TcpStream`] provide functionality for communication over TCP
9+
//! * [`UdpSocket`] and [`UdpFramed`] provide functionality for communication over UDP
10+
//! * [`UnixListener`] and [`UnixStream`] provide functionality for communication over a
11+
//! Unix Domain Socket **(available on Unix only)**
1112
//!
12-
//! To listen on an address [`TcpListener`] can be used. `TcpListener`'s
13-
//! [`incoming`][incoming_method] method can be used to accept new connections.
14-
//! It return the [`Incoming`] struct, which implements a stream which returns
15-
//! `TcpStream`s.
16-
//!
17-
//! [`TcpStream`]: struct.TcpStream.html
18-
//! [`connect`]: struct.TcpStream.html#method.connect
19-
//! [`ConnectFuture`]: struct.ConnectFuture.html
2013
//! [`TcpListener`]: struct.TcpListener.html
21-
//! [incoming_method]: struct.TcpListener.html#method.incoming
22-
//! [`Incoming`]: struct.Incoming.html
23-
//!
24-
//! # UDP
25-
//!
26-
//! The main struct for UDP is the [`UdpSocket`], which represents a UDP socket.
27-
//! Reading and writing to it can be done using futures, which return the
28-
//! [`RecvDgram`] and [`SendDgram`] structs respectively.
29-
//!
30-
//! For convenience it's also possible to convert raw datagrams into higher-level
31-
//! frames.
32-
//!
14+
//! [`TcpStream`]: struct.TcpStream.html
3315
//! [`UdpSocket`]: struct.UdpSocket.html
34-
//! [`RecvDgram`]: struct.RecvDgram.html
35-
//! [`SendDgram`]: struct.SendDgram.html
3616
//! [`UdpFramed`]: struct.UdpFramed.html
37-
//! [`framed`]: struct.UdpSocket.html#method.framed
17+
//! [`UnixListener`]: struct.UnixListener.html
18+
//! [`UnixStream`]: struct.UnixStream.html
3819
39-
pub use tokio_tcp::{TcpStream, ConnectFuture};
40-
pub use tokio_tcp::{TcpListener, Incoming};
41-
pub use tokio_udp::{UdpSocket, UdpFramed, SendDgram, RecvDgram};
20+
pub mod tcp {
21+
//! TCP bindings for `tokio`.
22+
//!
23+
//! Connecting to an address, via TCP, can be done using [`TcpStream`]'s
24+
//! [`connect`] method, which returns [`ConnectFuture`]. `ConnectFuture`
25+
//! implements a future which returns a `TcpStream`.
26+
//!
27+
//! To listen on an address [`TcpListener`] can be used. `TcpListener`'s
28+
//! [`incoming`][incoming_method] method can be used to accept new connections.
29+
//! It return the [`Incoming`] struct, which implements a stream which returns
30+
//! `TcpStream`s.
31+
//!
32+
//! [`TcpStream`]: struct.TcpStream.html
33+
//! [`connect`]: struct.TcpStream.html#method.connect
34+
//! [`ConnectFuture`]: struct.ConnectFuture.html
35+
//! [`TcpListener`]: struct.TcpListener.html
36+
//! [incoming_method]: struct.TcpListener.html#method.incoming
37+
//! [`Incoming`]: struct.Incoming.html
38+
pub use tokio_tcp::{ConnectFuture, Incoming, TcpListener, TcpStream};
39+
}
40+
pub use self::tcp::{TcpListener, TcpStream};
41+
42+
#[deprecated(note = "use `tokio::net::tcp::ConnectFuture` instead")]
43+
#[doc(hidden)]
44+
pub type ConnectFuture = self::tcp::ConnectFuture;
45+
#[deprecated(note = "use `tokio::net::tcp::Incoming` instead")]
46+
#[doc(hidden)]
47+
pub type Incoming = self::tcp::Incoming;
48+
49+
pub mod udp {
50+
//! UDP bindings for `tokio`.
51+
//!
52+
//! The main struct for UDP is the [`UdpSocket`], which represents a UDP socket.
53+
//! Reading and writing to it can be done using futures, which return the
54+
//! [`RecvDgram`] and [`SendDgram`] structs respectively.
55+
//!
56+
//! For convenience it's also possible to convert raw datagrams into higher-level
57+
//! frames.
58+
//!
59+
//! [`UdpSocket`]: struct.UdpSocket.html
60+
//! [`RecvDgram`]: struct.RecvDgram.html
61+
//! [`SendDgram`]: struct.SendDgram.html
62+
//! [`UdpFramed`]: struct.UdpFramed.html
63+
//! [`framed`]: struct.UdpSocket.html#method.framed
64+
pub use tokio_udp::{RecvDgram, SendDgram, UdpFramed, UdpSocket};
65+
}
66+
pub use self::udp::{UdpFramed, UdpSocket};
67+
68+
#[deprecated(note = "use `tokio::net::udp::RecvDgram` instead")]
69+
#[doc(hidden)]
70+
pub type RecvDgram<T> = self::udp::RecvDgram<T>;
71+
#[deprecated(note = "use `tokio::net::udp::SendDgram` instead")]
72+
#[doc(hidden)]
73+
pub type SendDgram<T> = self::udp::SendDgram<T>;
4274

4375
#[cfg(unix)]
4476
pub mod unix {
45-
//! Unix domain socket bindings for `tokio`.
77+
//! Unix domain socket bindings for `tokio` (only available on unix systems).
4678
4779
pub use tokio_uds::{
4880
ConnectFuture, Incoming, RecvDgram, SendDgram, UCred, UnixDatagram, UnixListener,
4981
UnixStream,
5082
};
5183
}
52-
5384
#[cfg(unix)]
5485
pub use self::unix::{UnixListener, UnixStream};

0 commit comments

Comments
 (0)