Document Handle::default() behavior (#359)

This commit is contained in:
main()
2018-05-14 11:11:28 -07:00
committed by Carl Lerche
parent 1f5bb121e2
commit 35f3351c97
4 changed files with 8 additions and 2 deletions
+4
View File
@@ -94,6 +94,9 @@ pub struct Reactor {
/// A `Handle` is used for associating I/O objects with an event loop /// A `Handle` is used for associating I/O objects with an event loop
/// explicitly. Typically though you won't end up using a `Handle` that often /// explicitly. Typically though you won't end up using a `Handle` that often
/// and will instead use the default reactor for the execution context. /// and will instead use the default reactor for the execution context.
///
/// By default, most components bind lazily to reactors.
/// To get this behavior when manually passing a `Handle`, use `default()`.
#[derive(Clone)] #[derive(Clone)]
pub struct Handle { pub struct Handle {
inner: Option<HandlePriv>, inner: Option<HandlePriv>,
@@ -475,6 +478,7 @@ impl Unpark for Handle {
} }
impl Default for Handle { impl Default for Handle {
/// Returns a "default" handle, i.e., a handle that lazily binds to a reactor.
fn default() -> Handle { fn default() -> Handle {
Handle { inner: None } Handle { inner: None }
} }
+1
View File
@@ -159,6 +159,7 @@ impl TcpListener {
/// ///
/// Finally, the `handle` argument is the event loop that this listener will /// Finally, the `handle` argument is the event loop that this listener will
/// be bound to. /// be bound to.
/// Use `Handle::default()` to lazily bind to an event loop, just like `bind` does.
/// ///
/// The platform specific behavior of this function looks like: /// The platform specific behavior of this function looks like:
/// ///
+1 -2
View File
@@ -69,8 +69,7 @@ impl TcpStream {
/// ///
/// This function will convert a TCP stream created by the standard library /// This function will convert a TCP stream created by the standard library
/// to a TCP stream ready to be used with the provided event loop handle. /// to a TCP stream ready to be used with the provided event loop handle.
/// The stream returned is associated with the event loop and ready to /// Use `Handle::default()` to lazily bind to an event loop, just like `connect` does.
/// perform I/O.
pub fn from_std(stream: net::TcpStream, handle: &Handle) pub fn from_std(stream: net::TcpStream, handle: &Handle)
-> io::Result<TcpStream> -> io::Result<TcpStream>
{ {
+2
View File
@@ -36,6 +36,8 @@ 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.
///
/// Use `Handle::default()` to lazily bind to an event loop, just like `bind` does.
pub fn from_std(socket: net::UdpSocket, pub fn from_std(socket: net::UdpSocket,
handle: &Handle) -> io::Result<UdpSocket> { handle: &Handle) -> io::Result<UdpSocket> {
let io = mio::net::UdpSocket::from_socket(socket)?; let io = mio::net::UdpSocket::from_socket(socket)?;