Skip to main content

telepath_server/
transport.rs

1//! Non-blocking byte-stream transport trait.
2//!
3//! Any byte-stream I/O source/sink implements [`Transport`]. For nRF52840-DK,
4//! see `rtt_transport::RttTransport` in the example crate.
5
6/// Non-blocking byte-stream transport.
7///
8/// Both methods are non-blocking and return the number of bytes transferred.
9/// Returning `0` means no bytes were available (read) or the sink was full
10/// (write). Callers must poll in a loop rather than block.
11pub trait Transport {
12    /// Read up to `buf.len()` bytes. Returns the number of bytes read.
13    /// Returns `0` if no data is currently available.
14    fn read(&mut self, buf: &mut [u8]) -> usize;
15
16    /// Write up to `buf.len()` bytes. Returns the number of bytes written.
17    /// May return less than `buf.len()` if the sink buffer is full.
18    fn write(&mut self, buf: &[u8]) -> usize;
19}