serial_core/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Core types shared by serial port implementations and users.
5
6#![forbid(unsafe_code)]
7
8pub mod disconnected;
9pub mod resources;
10pub mod serial_io;
11
12use futures::io::AsyncRead;
13use futures::io::AsyncWrite;
14use inspect::InspectMut;
15use std::task::Context;
16use std::task::Poll;
17
18/// Trait for types providing serial IO.
19pub trait SerialIo: AsyncRead + AsyncWrite + Send + InspectMut + Unpin {
20    /// Returns true if the backend is already connected.
21    fn is_connected(&self) -> bool;
22
23    /// Polls for the serial backend to connect.
24    ///
25    /// When the serial backend disconnects, [`AsyncRead::poll_read`] should
26    /// return `Ok(0)`.
27    fn poll_connect(&mut self, cx: &mut Context<'_>) -> Poll<std::io::Result<()>>;
28
29    /// Polls for the serial backend to disconnect.
30    fn poll_disconnect(&mut self, cx: &mut Context<'_>) -> Poll<std::io::Result<()>>;
31}