/rust/registry/src/index.crates.io-6f17d22bba15001f/cap-std-3.4.4/src/net/incoming.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::net::TcpStream; |
2 | | use std::{fmt, io, net}; |
3 | | |
4 | | /// An iterator that infinitely `accept`s connections on a [`TcpListener`]. |
5 | | /// |
6 | | /// This corresponds to [`std::net::Incoming`]. |
7 | | /// |
8 | | /// [`TcpListener`]: struct.TcpListener.html |
9 | | pub struct Incoming<'a> { |
10 | | std: net::Incoming<'a>, |
11 | | } |
12 | | |
13 | | impl<'a> Incoming<'a> { |
14 | | /// Constructs a new instance of `Self` from the given |
15 | | /// `std::net::Incoming`. |
16 | | /// |
17 | | /// This grants access the resources the `std::net::Incoming` instance |
18 | | /// already has access to. |
19 | | #[inline] |
20 | 0 | pub fn from_std(std: net::Incoming<'a>) -> Self { |
21 | 0 | Self { std } |
22 | 0 | } |
23 | | } |
24 | | |
25 | | impl<'a> Iterator for Incoming<'a> { |
26 | | type Item = io::Result<TcpStream>; |
27 | | |
28 | | #[inline] |
29 | 0 | fn next(&mut self) -> Option<Self::Item> { |
30 | 0 | self.std.next().map(|result| { |
31 | 0 | let tcp_stream = result?; |
32 | 0 | Ok(TcpStream::from_std(tcp_stream)) |
33 | 0 | }) |
34 | 0 | } |
35 | | |
36 | | #[inline] |
37 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
38 | 0 | self.std.size_hint() |
39 | 0 | } |
40 | | } |
41 | | |
42 | | impl<'a> fmt::Debug for Incoming<'a> { |
43 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
44 | 0 | self.std.fmt(f) |
45 | 0 | } |
46 | | } |