Trait TcpConnection

Source
pub trait TcpConnection:
    Debug
    + Read<Error = Error>
    + Write
    + ErrorType {
    // Required method
    async fn close(self);
}
Expand description

TCP connection for reading and writing data.

Implements async read and write operations through embedded_io_async traits.

§Example

use embedded_io_async::{Read, Write};
use veecle_osal_api::net::tcp::TcpConnection;

async fn echo_server(mut connection: impl TcpConnection)
{
    let mut buffer = [0u8; 1024];
    loop {
        match connection.read(&mut buffer).await {
            Ok(0) => break, // Connection closed.
            Ok(read) => {
                connection.write_all(&buffer[..read]).await.unwrap();
                connection.flush().await.unwrap();
            }
            Err(_) => break,
        }
    }
    connection.close().await;
}

Required Methods§

Source

async fn close(self)

Closes the write-half of the TCP connection and flushes all unsent data.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl<'a, 's> TcpConnection for veecle_os::osal::embassy::net::tcp::TcpConnection<'a, 's>

Source§

impl<'s> TcpConnection for veecle_os::osal::std::net::tcp::TcpConnection<'s>