diff --git a/Cargo.toml b/Cargo.toml index caa6c5c..6cc094a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,6 +60,10 @@ version = "0.4" [dependencies.cfg-if] version = "1" +[dependencies.serialport] +version = "4" +default-features = false + [dev-dependencies] anyhow = "1.0.91" diff --git a/src/lib.rs b/src/lib.rs index 6f9ac2e..ee3198d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,7 @@ pub use mio_serial::{ use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; +use std::convert::TryFrom; use std::io::{Read, Result as IoResult, Write}; use std::pin::Pin; use std::task::{Context, Poll}; @@ -488,6 +489,18 @@ impl Write for SerialStream { } } +#[cfg(unix)] +impl TryFrom for SerialStream { + type Error = Error; + + fn try_from(value: serialport::TTYPort) -> std::result::Result { + let port = mio_serial::SerialStream::try_from(value)?; + Ok(Self { + inner: AsyncFd::new(port)?, + }) + } +} + #[cfg(unix)] mod sys { use super::SerialStream;