//! Abstract async transport trait — implemented by [`udp`] and [`serial`].

pub mod serial;
pub mod udp;

use async_trait::async_trait;

use shared::error::Result;

/// Asynchronous, bidirectional byte transport over UDP or serial.
///
/// Implementations are expected to be cancellation-safe at await points so the
/// run loop can drop them on shutdown.
#[async_trait]
pub trait Transport: Send + Sync {
    /// Read up to `buf.len()` bytes; returns the number actually read.
    async fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
    /// Write the entire `buf` to the peer.
    async fn write_all(&mut self, buf: &[u8]) -> Result<()>;
}
