Skip to content

Commit a78a33c

Browse files
Add Incoming doc examples
1 parent c35b9f6 commit a78a33c

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/libstd/sys/unix/ext/net.rs

+30-3
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,36 @@ impl<'a> IntoIterator for &'a UnixListener {
791791
}
792792
}
793793

794-
/// An iterator over incoming connections to a `UnixListener`.
794+
/// An iterator over incoming connections to a [`UnixListener`].
795795
///
796-
/// It will never return `None`.
796+
/// It will never return [`None`].
797+
///
798+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
799+
/// [`UnixListener`]: struct.UnixListener.html
800+
///
801+
/// # Examples
802+
///
803+
/// ```no_run
804+
/// use std::thread;
805+
/// use std::os::unix::net::{UnixStream, UnixListener};
806+
///
807+
/// fn handle_client(stream: UnixStream) {
808+
/// // ...
809+
/// }
810+
///
811+
/// let listener = UnixListener::bind("/path/to/the/socket").unwrap();
812+
///
813+
/// for stream in listener.incoming() {
814+
/// match stream {
815+
/// Ok(stream) => {
816+
/// thread::spawn(|| handle_client(stream));
817+
/// }
818+
/// Err(err) => {
819+
/// break;
820+
/// }
821+
/// }
822+
/// }
823+
/// ```
797824
#[derive(Debug)]
798825
#[stable(feature = "unix_socket", since = "1.10.0")]
799826
pub struct Incoming<'a> {
@@ -817,7 +844,7 @@ impl<'a> Iterator for Incoming<'a> {
817844
///
818845
/// # Examples
819846
///
820-
/// ```rust,no_run
847+
/// ```no_run
821848
/// use std::os::unix::net::UnixDatagram;
822849
///
823850
/// let socket = UnixDatagram::bind("/path/to/my/socket").unwrap();

0 commit comments

Comments
 (0)