mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
doc: document from_std functions panic (#2056)
Document that conversion from `std` types must be done from within the Tokio runtime context.
This commit is contained in:
committed by
Carl Lerche
parent
dcfa895b51
commit
d45f61c183
@@ -166,6 +166,14 @@ where
|
|||||||
E: Evented,
|
E: Evented,
|
||||||
{
|
{
|
||||||
/// Creates a new `PollEvented` associated with the default reactor.
|
/// Creates a new `PollEvented` associated with the default reactor.
|
||||||
|
///
|
||||||
|
/// # 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 new(io: E) -> io::Result<Self> {
|
pub fn new(io: E) -> io::Result<Self> {
|
||||||
let registration = Registration::new(&io)?;
|
let registration = Registration::new(&io)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|||||||
@@ -53,6 +53,15 @@ impl Registration {
|
|||||||
///
|
///
|
||||||
/// - `Ok` if the registration happened successfully
|
/// - `Ok` if the registration happened successfully
|
||||||
/// - `Err` if an error was encountered during registration
|
/// - `Err` if an error was encountered during registration
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// # 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 new<T>(io: &T) -> io::Result<Registration>
|
pub fn new<T>(io: &T) -> io::Result<Registration>
|
||||||
where
|
where
|
||||||
T: Evented,
|
T: Evented,
|
||||||
|
|||||||
@@ -195,6 +195,14 @@ impl TcpListener {
|
|||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// # 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::TcpListener) -> io::Result<TcpListener> {
|
pub fn from_std(listener: net::TcpListener) -> io::Result<TcpListener> {
|
||||||
let io = mio::net::TcpListener::from_std(listener)?;
|
let io = mio::net::TcpListener::from_std(listener)?;
|
||||||
let io = PollEvented::new(io)?;
|
let io = PollEvented::new(io)?;
|
||||||
|
|||||||
@@ -139,6 +139,22 @@ impl TcpStream {
|
|||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// # 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.
|
||||||
|
///
|
||||||
|
/// # 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::TcpStream) -> io::Result<TcpStream> {
|
pub fn from_std(stream: net::TcpStream) -> io::Result<TcpStream> {
|
||||||
let io = mio::net::TcpStream::from_stream(stream)?;
|
let io = mio::net::TcpStream::from_stream(stream)?;
|
||||||
let io = PollEvented::new(io)?;
|
let io = PollEvented::new(io)?;
|
||||||
|
|||||||
@@ -57,6 +57,14 @@ impl UdpSocket {
|
|||||||
/// This can be used in conjunction with net2's `UdpBuilder` interface to
|
/// This can be used in conjunction with net2's `UdpBuilder` interface to
|
||||||
/// configure a socket before it's handed off, such as setting options like
|
/// configure a socket before it's handed off, such as setting options like
|
||||||
/// `reuse_address` or binding to multiple addresses.
|
/// `reuse_address` or binding to multiple addresses.
|
||||||
|
///
|
||||||
|
/// # 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(socket: net::UdpSocket) -> io::Result<UdpSocket> {
|
pub fn from_std(socket: net::UdpSocket) -> io::Result<UdpSocket> {
|
||||||
let io = mio::net::UdpSocket::from_socket(socket)?;
|
let io = mio::net::UdpSocket::from_socket(socket)?;
|
||||||
let io = PollEvented::new(io)?;
|
let io = PollEvented::new(io)?;
|
||||||
|
|||||||
@@ -45,6 +45,14 @@ impl UnixDatagram {
|
|||||||
///
|
///
|
||||||
/// The returned datagram will be associated with the given event loop
|
/// The returned datagram will be associated with the given event loop
|
||||||
/// specified by `handle` and is ready to perform I/O.
|
/// 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> {
|
pub fn from_std(datagram: net::UnixDatagram) -> io::Result<UnixDatagram> {
|
||||||
let socket = mio_uds::UnixDatagram::from_datagram(datagram)?;
|
let socket = mio_uds::UnixDatagram::from_datagram(datagram)?;
|
||||||
let io = PollEvented::new(socket)?;
|
let io = PollEvented::new(socket)?;
|
||||||
|
|||||||
@@ -21,6 +21,14 @@ cfg_uds! {
|
|||||||
|
|
||||||
impl UnixListener {
|
impl UnixListener {
|
||||||
/// Creates a new `UnixListener` bound to the specified path.
|
/// 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>
|
pub fn bind<P>(path: P) -> io::Result<UnixListener>
|
||||||
where
|
where
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
@@ -35,6 +43,14 @@ impl UnixListener {
|
|||||||
///
|
///
|
||||||
/// The returned listener will be associated with the given event loop
|
/// The returned listener will be associated with the given event loop
|
||||||
/// specified by `handle` and is ready to perform I/O.
|
/// 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> {
|
pub fn from_std(listener: net::UnixListener) -> io::Result<UnixListener> {
|
||||||
let listener = mio_uds::UnixListener::from_listener(listener)?;
|
let listener = mio_uds::UnixListener::from_listener(listener)?;
|
||||||
let io = PollEvented::new(listener)?;
|
let io = PollEvented::new(listener)?;
|
||||||
|
|||||||
@@ -47,6 +47,14 @@ impl UnixStream {
|
|||||||
///
|
///
|
||||||
/// The returned stream will be associated with the given event loop
|
/// The returned stream will be associated with the given event loop
|
||||||
/// specified by `handle` and is ready to perform I/O.
|
/// 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> {
|
pub fn from_std(stream: net::UnixStream) -> io::Result<UnixStream> {
|
||||||
let stream = mio_uds::UnixStream::from_stream(stream)?;
|
let stream = mio_uds::UnixStream::from_stream(stream)?;
|
||||||
let io = PollEvented::new(stream)?;
|
let io = PollEvented::new(stream)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user