11use crate :: SocketAddr ;
22
3+ /// Represents specific errors encountered during TCP operations.
4+ #[ non_exhaustive]
5+ #[ derive( Copy , Clone , PartialEq , Debug ) ]
6+ pub enum TcpErrorKind {
7+ /// The socket has been closed in the direction in which the failing operation was attempted.
8+ PipeClosed ,
9+
10+ /// Some other error has occurred.
11+ Other ,
12+ }
13+
14+ /// Methods to resolve errors into identifiable, actionable codes on the client side.
15+ pub trait TcpError : core:: fmt:: Debug {
16+ /// Determines the kind of error that occurred.
17+ fn kind ( & self ) -> TcpErrorKind ;
18+ }
19+
320/// This trait is implemented by TCP/IP stacks. You could, for example, have an implementation
421/// which knows how to send AT commands to an ESP8266 WiFi module. You could have another implementation
522/// which knows how to driver the Rust Standard Library's `std::net` module. Given this trait, you can
@@ -8,7 +25,7 @@ pub trait TcpClientStack {
825 /// The type returned when we create a new TCP socket
926 type TcpSocket ;
1027 /// The type returned when we have an error
11- type Error : core :: fmt :: Debug ;
28+ type Error : TcpError ;
1229
1330 /// Open a socket for usage as a TCP client.
1431 ///
@@ -27,9 +44,6 @@ pub trait TcpClientStack {
2744 remote : SocketAddr ,
2845 ) -> nb:: Result < ( ) , Self :: Error > ;
2946
30- /// Check if this socket is connected
31- fn is_connected ( & mut self , socket : & Self :: TcpSocket ) -> Result < bool , Self :: Error > ;
32-
3347 /// Write to the stream.
3448 ///
3549 /// Returns the number of bytes written (which may be less than `buffer.len()`) or an error.
@@ -98,10 +112,6 @@ impl<T: TcpClientStack> TcpClientStack for &mut T {
98112 T :: connect ( self , socket, remote)
99113 }
100114
101- fn is_connected ( & mut self , socket : & Self :: TcpSocket ) -> Result < bool , Self :: Error > {
102- T :: is_connected ( self , socket)
103- }
104-
105115 fn send (
106116 & mut self ,
107117 socket : & mut Self :: TcpSocket ,
0 commit comments