Skip to main content

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 debugger;
9pub mod disconnected;
10pub mod resources;
11pub mod serial_io;
12
13use futures::io::AsyncRead;
14use futures::io::AsyncWrite;
15use inspect::InspectMut;
16use std::task::Context;
17use std::task::Poll;
18
19/// Trait for types providing serial IO.
20pub trait SerialIo: AsyncRead + AsyncWrite + Send + InspectMut + Unpin {
21    /// Returns true if the backend is already connected.
22    fn is_connected(&self) -> bool;
23
24    /// Polls for the serial backend to connect.
25    ///
26    /// When the serial backend disconnects, [`AsyncRead::poll_read`] should
27    /// return `Ok(0)`.
28    fn poll_connect(&mut self, cx: &mut Context<'_>) -> Poll<std::io::Result<()>>;
29
30    /// Polls for the serial backend to disconnect.
31    fn poll_disconnect(&mut self, cx: &mut Context<'_>) -> Poll<std::io::Result<()>>;
32}