diff options
author | Stepan Koltsov <stepan.koltsov@gmail.com> | 2020-01-06 18:06:39 +0000 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2020-01-06 10:06:39 -0800 |
commit | d45f61c183b2e0bb0da196bdd13d77461dd03477 (patch) | |
tree | 88232363e6ba7ce30a7fb8177aba467b03008570 /tokio/src/net/unix | |
parent | dcfa895b512e3ed522b81b18baf3e33fd78a600c (diff) |
doc: document `from_std` functions panic (#2056)
Document that conversion from `std` types must be done from within
the Tokio runtime context.
Diffstat (limited to 'tokio/src/net/unix')
-rw-r--r-- | tokio/src/net/unix/datagram.rs | 8 | ||||
-rw-r--r-- | tokio/src/net/unix/listener.rs | 16 | ||||
-rw-r--r-- | tokio/src/net/unix/stream.rs | 8 |
3 files changed, 32 insertions, 0 deletions
diff --git a/tokio/src/net/unix/datagram.rs b/tokio/src/net/unix/datagram.rs index ae1372f6..b41ec87c 100644 --- a/tokio/src/net/unix/datagram.rs +++ b/tokio/src/net/unix/datagram.rs @@ -45,6 +45,14 @@ impl UnixDatagram { /// /// The returned datagram will be associated with the given event loop /// specified by `handle` and is ready to perform I/O. + /// + /// # Panics + /// + /// This function panics if thread-local runtime is not set. + /// + /// The runtime is usually set implicitly when this function is called + /// from a future driven by a tokio runtime, otherwise runtime can be set + /// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function. pub fn from_std(datagram: net::UnixDatagram) -> io::Result<UnixDatagram> { let socket = mio_uds::UnixDatagram::from_datagram(datagram)?; let io = PollEvented::new(socket)?; diff --git a/tokio/src/net/unix/listener.rs b/tokio/src/net/unix/listener.rs index 4b93bf82..d61d0392 100644 --- a/tokio/src/net/unix/listener.rs +++ b/tokio/src/net/unix/listener.rs @@ -21,6 +21,14 @@ cfg_uds! { impl UnixListener { /// Creates a new `UnixListener` bound to the specified path. + /// + /// # Panics + /// + /// This function panics if thread-local runtime is not set. + /// + /// The runtime is usually set implicitly when this function is called + /// from a future driven by a tokio runtime, otherwise runtime can be set + /// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function. pub fn bind<P>(path: P) -> io::Result<UnixListener> where P: AsRef<Path>, @@ -35,6 +43,14 @@ impl UnixListener { /// /// The returned listener will be associated with the given event loop /// specified by `handle` and is ready to perform I/O. + /// + /// # Panics + /// + /// This function panics if thread-local runtime is not set. + /// + /// The runtime is usually set implicitly when this function is called + /// from a future driven by a tokio runtime, otherwise runtime can be set + /// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function. pub fn from_std(listener: net::UnixListener) -> io::Result<UnixListener> { let listener = mio_uds::UnixListener::from_listener(listener)?; let io = PollEvented::new(listener)?; diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index 5151b08a..c21e71e3 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -47,6 +47,14 @@ impl UnixStream { /// /// The returned stream will be associated with the given event loop /// specified by `handle` and is ready to perform I/O. + /// + /// # Panics + /// + /// This function panics if thread-local runtime is not set. + /// + /// The runtime is usually set implicitly when this function is called + /// from a future driven by a tokio runtime, otherwise runtime can be set + /// explicitly with [`Handle::enter`](crate::runtime::Handle::enter) function. pub fn from_std(stream: net::UnixStream) -> io::Result<UnixStream> { let stream = mio_uds::UnixStream::from_stream(stream)?; let io = PollEvented::new(stream)?; |