pub trait TcpStack {
type TcpSocket;
type Error: Into<TcpError> + Debug;
// Required methods
fn open(&self, mode: Mode) -> Result<Self::TcpSocket, Self::Error>;
fn connect(
&self,
socket: Self::TcpSocket,
remote: HostSocketAddr,
) -> Result<Self::TcpSocket, Self::Error>;
fn is_connected(
&self,
socket: &Self::TcpSocket,
) -> Result<bool, Self::Error>;
fn write(
&self,
socket: &mut Self::TcpSocket,
buffer: &[u8],
) -> Result<usize, Self::Error>;
fn read(
&self,
socket: &mut Self::TcpSocket,
buffer: &mut [u8],
) -> Result<usize, Self::Error>;
fn close(&self, socket: Self::TcpSocket) -> Result<(), Self::Error>;
}Expand description
This trait is implemented by TCP/IP stacks. You could, for example, have an implementation
which knows how to send AT commands to an ESP8266 WiFi module. You could have another implemenation
which knows how to driver the Rust Standard Library’s std::net module. Given this trait, you can how
write a portable HTTP client which can work with either implementation.
Required Associated Types§
Required Methods§
Sourcefn open(&self, mode: Mode) -> Result<Self::TcpSocket, Self::Error>
fn open(&self, mode: Mode) -> Result<Self::TcpSocket, Self::Error>
Open a new TCP socket. The socket starts in the unconnected state.
Sourcefn connect(
&self,
socket: Self::TcpSocket,
remote: HostSocketAddr,
) -> Result<Self::TcpSocket, Self::Error>
fn connect( &self, socket: Self::TcpSocket, remote: HostSocketAddr, ) -> Result<Self::TcpSocket, Self::Error>
Connect to the given remote host and port.
Sourcefn is_connected(&self, socket: &Self::TcpSocket) -> Result<bool, Self::Error>
fn is_connected(&self, socket: &Self::TcpSocket) -> Result<bool, Self::Error>
Check if this socket is connected
Sourcefn write(
&self,
socket: &mut Self::TcpSocket,
buffer: &[u8],
) -> Result<usize, Self::Error>
fn write( &self, socket: &mut Self::TcpSocket, buffer: &[u8], ) -> Result<usize, Self::Error>
Write to the stream. Returns the number of bytes written is returned
(which may be less than buffer.len()), or an error.